标签:turn ret const js函数 函数 s函数 curry function func
//自行实现以下curry函数和compose
//curry
function curry(fn) {
return function aa (...arg) {
if (arg.length >= fn.length) {
return fn(...arg);
} else {
return aa.bind(null, ...arg);
}
}
}
const curry = (fn) => aa = (...arg) => arg.length >= fn.length ? fn(...arg): aa.bind(null, ...arg);
// compose
function compose(...arr) {
return function (...arr2) {
(function aa(n) {
if (n < arr.length -1) {
return arr[n](aa(++n))
} else {
return arr[n](...arr2);
}
})(0)
}
}
const compose = (...arr) => (...arr2) => ((aa = (n) => n < arr.length - 1 ? arr[n](aa(++n)): arr[n](...arr2))(0));
标签:turn ret const js函数 函数 s函数 curry function func
原文地址:https://www.cnblogs.com/sgqwjr/p/10294176.html