Ad
Code
Diff
  • const curry = (f, xs = []) => (...args) =>
      (xs.length + args.length) >= f.length
      ? f(...xs, ...args)
      : curry(f, xs.concat(args))
    • const fn = (f) => (...args) => args.reduce((f, arg) => f(arg), f);
    • // ==================================
    • const sum = fn(a => b => c => (a + b + c));
    • console.log(sum(1, 2, 3)); // 6
    • console.log(sum(1, 2)(3)); // 6
    • console.log(sum(1)(2)(3)); // 6
    • const doubleInc = sum(1)(1);
    • console.log(doubleInc(4)); // 6
    • const curry = (f, xs = []) => (...args) =>
    • (xs.length + args.length) >= f.length
    • ? f(...xs, ...args)
    • : curry(f, xs.concat(args))