curry and partial
by Artem
JavaScript
'use strict';
const partial = (fn, ...args) => (...n) => fn(...args, ...n);
const curry = (fn) => {
const inner = (...args) => {
if (args.length < fn.length) {
return (...n) => inner(...args, ...n);
}
return fn(...args);
};
return inner;
};
const partial = () => {
// your code...
};
// cleint code
const fn = (a, b, c, d) => a + b + c + d;
const part = partial(fn, 1, 2);
part(3, 4); // 10
const curried = curry(fn);
const fn1 = curried(1, 2);
const fn2 = fn1(3);
const res = fn2(4);
console.log(res);