function
var abc = function (a, b, c) {
return [a, b, c];
};
var curried = _.curry(abc);
curried(1)(2)(3);
// => [1, 2, 3]
curried(1, 2)(3);
// => [1, 2, 3]
curried(1, 2, 3);
// => [1, 2, 3]
// Curried with placeholders.
curried(1)(_, 3)(2);
// => [1, 2, 3]
function curry(func) {
let curried = (...args) => {
if (func.length > args.length) {
return (...reset) => curried(...args, ...reset);
}
return func(...args);
};
return curried;
}
// compose
function sum(a,b) {
return a + b
}
function len(str){
return str.length
}
function addPrefix(str) {
return `$${str}`
}
const compose = (...fns) => {
return fns.reduce((prev, next)) => (...args) => prev(next(...args))
}
// 从右往左执行
let final = compose(addPrefix, len, sum)