mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problems(js): add “2632. Curry”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
dd5aeef5f6
commit
ac8a1720ef
1 changed files with 19 additions and 0 deletions
19
problems/curry.js
Normal file
19
problems/curry.js
Normal 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
|
||||
*/
|
Loading…
Reference in a new issue