Skip to content

Commit c783706

Browse files
Time: 77 ms (26.50%), Space: 48 MB (62.04%) - LeetHub
1 parent ae1bde9 commit c783706

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2632-curry/2632-curry.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {Function} fn
3+
* @return {Function}
4+
*/
5+
var curry = function (fn) {
6+
return function curried(...args) {
7+
if (fn.length === args.length) {
8+
return fn(...args);
9+
} else {
10+
return function (...newArgs) {
11+
return curried(...args, ...newArgs);
12+
};
13+
}
14+
};
15+
};
16+
17+
/**
18+
* function sum(a, b) { return a + b; }
19+
* const csum = curry(sum);
20+
* csum(1)(2) // 3
21+
*/

0 commit comments

Comments
 (0)