Curry

Benchmark created on


Setup

function curry (fn) {
      var args1 = Array.prototype.slice.call(arguments, 1);
      return function () {
        var args2 = Array.prototype.slice.call(arguments, 0);
        return fn.apply(null, args1.concat(args2)) 
      } 
    }
    
    var add = function (a, b) { return a + b }
    
    var adder1 = curry(add, 2);
    
    var adder2 = function () {  
        var args2 = Array.prototype.slice.call(arguments, 0);
        return add.apply(null, [2].concat(args2)) 
    }
    
    var adder3Args = [2];
    var adder3 = function () {  
        var args2 = Array.prototype.slice.call(arguments, 0);
        return add.apply(null, adder3Args.concat(args2)) 
    }

Test runner

Ready to run.

Testing in
TestOps/sec
1
adder1(3)
ready
2
adder2(3)
ready
3
adder3(3)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.