js 函数式编程问题

在codewars上看到的一道函数式编程题
要求写出0~9十个函数和加减乘除四个函数,最终实现以下功能
seven(times(five()));//mustreturn35
four(plus(nine()));//mustreturn13
eight(minus(three()));//mustreturn5
six(dividedBy(two()));//mustreturn3
有点绕晕了,麻烦大能解惑下,不胜感激。
撒科打诨
浏览 345回答 2
2回答

回首忆惘然

大概这个意思吧.functionone(fun){if(fun)returnfun(1);return1;}functiontwo(fun){if(fun)returnfun(2);return2;}functionplus(num){returnfunction(a){returna+num;}}one(plus(two()));

慕娘9325324

对js不熟,应该是这样:functionpartial_op_with_oper2(op,oper2){returnfunction(oper1){returnop(oper1,oper2);};}functionmake_operand(value){returnfunction(oper2){if(oper2){returnoper2(value);}else{returnvalue;}};}//"Operators"vartimes=function(b){varop=function(a,b){returna*b;};returnpartial_op_with_oper2(op,b);};varplus=function(b){varop=function(a,b){returna+b;};returnpartial_op_with_oper2(op,b);};//"Operands"varzero=make_operand(0);varone=make_operand(1);vartwo=make_operand(2);varthree=make_operand(3);varfour=make_operand(4);varfive=make_operand(5);varsix=make_operand(6);varseven=make_operand(7);vareight=make_operand(8);varnine=make_operand(9);跟@brayden的一个意思
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript