Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e486edb

Browse files
committed
Add solution #2632
1 parent b1d45cf commit e486edb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,7 @@
19741974
2629|[Function Composition](./solutions/2629-function-composition.js)|Easy|
19751975
2630|[Memoize II](./solutions/2630-memoize-ii.js)|Hard|
19761976
2631|[Group By](./solutions/2631-group-by.js)|Medium|
1977+
2632|[Curry](./solutions/2632-curry.js)|Medium|
19771978
2634|[Filter Elements from Array](./solutions/2634-filter-elements-from-array.js)|Easy|
19781979
2635|[Apply Transform Over Each Element in Array](./solutions/2635-apply-transform-over-each-element-in-array.js)|Easy|
19791980
2636|[Promise Pool](./solutions/2636-promise-pool.js)|Medium|

solutions/2632-curry.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 2632. Curry
3+
* https://leetcode.com/problems/curry/
4+
* Difficulty: Medium
5+
*
6+
* Given a function fn, return a curried version of that function.
7+
*
8+
* A curried function is a function that accepts fewer or an equal number of parameters as the
9+
* original function and returns either another curried function or the same value the original
10+
* function would have returned.
11+
*
12+
* In practical terms, if you called the original function like sum(1,2,3), you would call the
13+
* curried version like csum(1)(2)(3), csum(1)(2,3), csum(1,2)(3), or csum(1,2,3). All these
14+
* methods of calling the curried function should return the same value as the original.
15+
*/
16+
17+
/**
18+
* @param {Function} fn
19+
* @return {Function}
20+
*/
21+
var curry = function(fn) {
22+
return function curried(...args) {
23+
if (args.length >= fn.length) {
24+
return fn(...args);
25+
}
26+
return (...nextArgs) => curried(...args, ...nextArgs);
27+
};
28+
};

0 commit comments

Comments
 (0)