发布于 1970-01-01 08:00
  • 7 个回答
    • 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;
         };
      
      2022-11-24 15:45 回答
    • 没有使用价值,不必纠结

      2022-11-24 15:45 回答
    • 十个数字函数,四个操作函数,思路最简单的话这样就行。。

      function one(x){
          if(x == null){
              return 1;
          }else{
              return eval('1'+x);
          }
      }
      function two(x){
          if(x == null){
              return 2;
          }else{
              return eval('2'+x);
          }
      }
      function three(x){
          if(x == null){
              return 3;
          }else{
              return eval('3'+x);
          }
      }
      function four(x){
          if(x == null){
              return 4;
          }else{
              return eval('4'+x);
          }
      }
      function five(x){
          if(x == null){
              return 5;
          }else{
              return eval('5'+x);
          }
      }
      function six(x){
          if(x == null){
              return 6;
          }else{
              return eval('6'+x);
          }
      }
      function seven(x){
          if(x == null){
              return 7;
          }else{
              return eval('7'+x);
          }
      }
      function eight(x){
          if(x == null){
              return 8;
          }else{
              return eval('8'+x);
          }
      }
      function nine(x){
          if(x == null){
              return 9;
          }else{
              return eval('9'+x);
          }
      }
      function zero(x){
          if(x == null){
              return 0;
          }else{
              return eval('0'+x);
          }
      }
      function minus(x){
          return '-'+x;
      }
      function times(x){
          return '*'+x;
      }
      function plus(x){
          return '+'+x;
      }
      function pidedBy(x){
          return '/'+x;
      }
      
      2022-11-24 15:45 回答
    • 感觉 @Theo 做的还不是特别彻底.

      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;
      });
      
      2022-11-24 15:45 回答
    • 正确答案

      var names = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
      
      names.forEach(function (name, i) {
        window[name] = function (fn) {
          if (!fn) return i + 1;
          return fn(i + 1);
        }
      })
      
      function times(i) {
        return function (j) {
          return i*j;
        }
      }
      
      function plus(i) {
        return function (j) {
          return i+j;
        }
      }
      
      function minus(i) {
        return function (j) {
          return j-i;
        }
      }
      
      function pidedBy(i) {
        return function (j) {
          return j/i;
        }
      }
      
      2022-11-24 15:45 回答
    • 对js不熟,应该是这样:

      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);
      

      跟 @brayden 的一个意思

      2022-11-24 15:45 回答
    • 大概这个意思吧.

      function one(fun)
      {
          if(fun) return fun(1); 
          return 1;
      }
      
      function two(fun)
      {
          if(fun) return fun(2); 
          return 2;
      }
      
      function plus(num)
      {
          return function(a){return a + num;}
      }
      
      one(plus(two()));
      
      2022-11-24 15:45 回答
    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有