Passing additional parameters in higher-order functions

前端 未结 6 1433
刺人心
刺人心 2020-12-13 11:01

Consider this example:



        
6条回答
  •  不知归路
    2020-12-13 12:05

    Here's another version with a primitive curry function:

    const samples = ["foo", "bar"];
    
    const exclude = function(item,str) {
      return item !== str;
    }
    
    function curry(func){
      return function(var1){
        return function(var2){
          return func(var1,var2); 
        };
      };
    }
    
    console.log(curry(exclude)('foo')('bar'));  // true
    console.log(samples.filter(curry(exclude)('foo')));  // ["bar"]

提交回复
热议问题