MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/node/comments/1c3uaey/javascript_functions_4_ways/kzlaa65/?context=3
r/node • u/hoonerismsmeen • Apr 14 '24
79 comments sorted by
View all comments
-1
I don't think I would've used arrow functions as the final two ways.
Definitely would've gone with partial application
let __map = [].map; function map (list, unaryFn) { return __map.call(list, unaryFn); }; function square (n) { return n * n; }; map([1, 2, 3], square);
and currying
function curry (binaryFn) { return function (firstArg) { return function (secondArg) { return binaryFn(firstArg, secondArg); }; }; }; let curriedMap = curry(map), double = function (n) { return n + n; }; let oneToThreeEach = curriedMap([1, 2, 3]); oneToThreeEach(square); //=> [1, 4, 9] oneToThreeEach(double); //=> [2, 4, 6]
source
-1
u/SponsoredByMLGMtnDew Apr 14 '24
I don't think I would've used arrow functions as the final two ways.
Definitely would've gone with partial application
and currying
source