function curry(fn) { return function cb (...args) { if(args.length >= fn.length) { return fn(...args) } else { return (...arg) => cb(...args, ...arg) } } } var demo = function (x, y, z) { return x + y + z } var curryFn = curry(demo) console.log(curryFn(3)(2)(5))