我正在学习函数式编程,我想知道是否有办法"组合"这样的函数:
function triple(x) {
return x * 3;
}
function plusOne(x) {
return x + 1;
}
function isZero(x) {
return x === 0;
}
combine(1); //1
combine(triple)(triple)(plusOne)(1); // 10
combine(plusOne)(triple)(isZero)(-1); // true
Run Code Online (Sandbox Code Playgroud)
如果para是一个函数,它将函数"组合"到自身中,如果不是,它将返回最终结果.谢谢!
class Obj {
constructor() {
this.propA = ~~(Math.random() * 255 + 0.5);
this.propB = ~~(Math.random() * 300 + 0.5);
}
}
const arr1 = new Array(100000);
for (var i = 0; i < 100000; i ++) {
arr1[i] = new Obj();
}
function test1() {
let start = new Date();
for (var times = 0; times < 1000; times ++) {
let n = 0;
for (var i = 0; i < 100000; i++) {
if (arr1[i].propA > arr1[i].propB) { …Run Code Online (Sandbox Code Playgroud)