steevehook
8/22/2018 - 9:23 PM

Curry n arry function

Curry n arry function

const curry = fn => {
  if (typeof fn !== "function") {
    throw new Error("No function provided");
  }

  return function curriedFn(...args) {
    return args.length < fn.length
      ? arg => curriedFn.apply(null, args.concat(arg))
      : fn.apply(null, args);
  };
};

const curried = curry((a, b, c, d) => a + b + c + d);
console.log(curried(1)(2)(3)(4)); // 10