pastebin

Paste Search Dynamic
callingMyFunc
  1. function sum(a, b, c) {
  2.   return a + b + c;
  3. }
  4. const myFunc = callback => {
  5.   let expectedArgs = 3
  6.   let currentArgs = []
  7.   const curry = (...args) => {
  8.     args = [...currentArgs, ...args]
  9.     if (args.length === expectedArgs) {
  10.       currentArgs = []
  11.       return callback(...args)
  12.     } else {
  13.       currentArgs = args
  14.       return curry
  15.     }
  16.   }
  17.   return curry
  18. }
  19. var callingMyFunc = myFunc(sum);
  20. console.log(callingMyFunc(1,2,3)); //-- 6
  21. console.log(callingMyFunc(1,3)(2)); //-- 6
  22. console.log(callingMyFunc(1)(2)(3)); //-- 6
Parsed in 0.004 seconds