Created
April 22, 2019 15:33
-
-
Save EminQasimov/7aef9becdf4b0956e747613235805868 to your computer and use it in GitHub Desktop.
Currying
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
function curry( fn ) { | |
var arity = fn.length; | |
return (function resolver() { | |
var memory = Array.prototype.slice.call( arguments ); | |
return function() { | |
var local = memory.slice(), next; | |
Array.prototype.push.apply( local, arguments ); | |
next = local.length >= arity ? fn : resolver; | |
return next.apply( null, local ); | |
}; | |
}()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment