timoxley / functional-javascript-workshop

A functional javascript workshop. No libraries required (i.e. no underscore), just ES5.
2.06k stars 441 forks source link

[Function Call] Many solutions possible, but which one is correct? #182

Open alejandroiglesias opened 7 years ago

alejandroiglesias commented 7 years ago

For the Function Call exercise, there are many possible solutions, but I would like to know which ones have fewer drawbacks.

Official solution:

module.exports = Function.call.bind(Array.prototype.slice)

My solution 1:

module.exports = (arr, start, end) => Function.prototype.call.call(Array.prototype.slice, arr, start, end)

My solution 2:

module.exports = (arr, start, end) => Array.prototype.slice.call(arr, start, end)

All three solutions work. Of course the first is the most beautiful and easier to read of the three, but I wonder if other than that there can be technical drawbacks. Also, I think this exercise could be presented earlier in the course since it's not as difficult as the previous one. Cheers.