problems(js): add “2632. Curry”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-05-14 11:00:17 +02:00
parent dd5aeef5f6
commit ac8a1720ef
Signed by: mfocko
GPG key ID: 7C47D46246790496

19
problems/curry.js Normal file
View file

@ -0,0 +1,19 @@
/**
* @param {Function} fn
* @return {Function}
*/
var curry = function(fn) {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args);
}
return curried.bind(this, ...args);
};
};
/**
* function sum(a, b) { return a + b; }
* const csum = curry(sum);
* csum(1)(2) // 3
*/