DEV Community

loading...

Discussion on: Daily Challenge #123 - Curry me Softly

Collapse
logycon profile image
Igor

Not really currying, but, in any case

function adder () {
  return [].slice.call(arguments).reduce(function(a,b){
    return a + b
  },0);
}

var curryAdder = function() {
  if (!curryAdder['acc']) curryAdder['acc'] = 0
  if (arguments.length > 0) {
    var args = [...arguments];
    curryAdder['acc'] += adder(...args);
    return curryAdder;
  } else {
    var ret = curryAdder['acc'];
    curryAdder['acc'] = 0;
    return ret;
  }
}

repl.it/@logycon/Daily-Challenge-123