Created
August 19, 2017 04:17
-
-
Save lili21/ec1e5ce7985a464183a3c8c2e10d9a90 to your computer and use it in GitHub Desktop.
infinite curry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function curry(fn) { | |
var _args = [] | |
return function _fn (...args) { | |
_args = [..._args, ...args] | |
if (args.length) { | |
return _fn | |
} else { | |
const r = _args.reduce(fn) | |
_args = [] | |
return r | |
//return (_args.reduce(fn)) | |
} | |
} | |
} | |
add = curry((a, b) => a + b) | |
console.log(add(1, 2, 3)()) | |
console.log(add(1)(2)(3, 4)()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment