Created
August 6, 2017 01:44
-
-
Save quieterkali/eccf5aecdccad540ec226359354d7ace to your computer and use it in GitHub Desktop.
custom curry funtion
This file contains 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
const curry = (fn) => { | |
if(typeof fn !== 'function') { | |
throw Error('No function provided'); | |
} | |
return function curriedFn(...args) { | |
if(args.length < fn.length) { | |
return function() { | |
return curriedFn.apply(null, args.concat([].slice.call(arguments))); | |
}; | |
} | |
return fn.apply(null, args); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
olha esse trecho:
if(args.length < fn.length) { return function() { return curriedFn.apply(null, args.concat([].slice.call(arguments))); }; }
porque nao simplesmente nao é:
`if(args.length < fn.length) {
}`
???