seven(times(five())); // must return 35
four(plus(nine())); // must return 13
eight(minus(three())); // must return 5
six(pidedBy(two())); // must return 3
function partial_op_with_oper2(op, oper2) {
return function(oper1) {
return op(oper1, oper2);
};
}
function make_operand(value) {
return function(oper2) {
if (oper2) {
return oper2(value);
} else {
return value;
}
};
}
// "Operators"
var times = function(b) {
var op = function(a, b) { return a * b; };
return partial_op_with_oper2(op, b);
};
var plus = function(b) {
var op = function(a, b) { return a + b; };
return partial_op_with_oper2(op, b);
};
// "Operands"
var zero = make_operand(0);
var one = make_operand(1);
var two = make_operand(2);
var three = make_operand(3);
var four = make_operand(4);
var five = make_operand(5);
var six = make_operand(6);
var seven = make_operand(7);
var eight = make_operand(8);
var nine = make_operand(9);
var createValue = function( v ) {
return function( f ) {
if ( typeof f === 'function' ) {
return f( v );
}
else return v;
};
};
var createAction = function( action ) {
return function(m) {
return function(n) {
return action( n, m );
};
};
};
var one = createValue( 1 )
var two = createValue( 2 );
var plus = createAction(function( m, n ) {
return m + n;
});
var minu = createAction(function( m, n ) {
return m - n;
});
function _num(num,fn){
if(typeof fn === 'function')return fn(num);
return num;
}
function zero(fn) {return _num(0,fn);}
function one(fn) {return _num(1,fn);}
function two(fn) {return _num(2,fn);}
function three(fn) {return _num(3,fn);}
function four(fn) {return _num(4,fn); }
function five(fn) {return _num(5,fn);}
function six(fn) {return _num(6,fn);}
function seven(fn) {return _num(7,fn);}
function eight(fn) {return _num(8,fn);}
function nine(fn) {return _num(9,fn);}
function plus(num) {
return function(a){
return a + num;
};
}
function minus(num) {
return function(a){
return a - num;
};
}
function times(num) {
return function(a){
return a * num;
};
}
function pidedBy(num) {
return function(a){
return a / num;
};
大概这个意思吧.
对js不熟,应该是这样:
跟 @brayden 的一个意思
正确答案
感觉 @Theo 做的还不是特别彻底.
十个数字函数,四个操作函数,思路最简单的话这样就行。。
没有使用价值,不必纠结