AlgoDaily Solution
1function curry(func) {
2 // ...args collects arguments as array
3 return function curriedFunc(...args) {
4 // Check if current args passed equals the number of args func expects
5 if (args.length >= func.length) {
6 // if args length equals the expected number, pass into func (spread)
7 return func(...args);
8 } else {
9 /* Else, we return a function that collects the next arguments passed and
10 recursively call curriedFunc */
11 return function (...next) {
12 return curriedFunc(...args, ...next);
13 };
14 }
15 };
16}
Community Solutions
Community solutions are only available for premium users.
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.
xxxxxxxxxx
17
function curry(func) {
// ...args collects arguments as array
return function curriedFunc(args) {
// Check if current args passed equals the number of args func expects
if (args.length >= func.length) {
// if args length equals the expected number, pass into func (spread)
return func(args);
} else {
/* Else, we return a function that collects the next arguments passed and
recursively call curriedFunc */
return function (next) {
return curriedFunc(args, next);
};
}
};
}
OUTPUT
Results will appear here.