Last active
November 7, 2016 18:44
-
-
Save edtsech/8fc3145f8ff47689b96e50dfe6cf995e to your computer and use it in GitHub Desktop.
A function which moves argument of passed function from the first position to the last position.
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
flipArgs = function (f) { | |
return function() { | |
let args = Array.prototype.slice.call(arguments); | |
return f.apply(null, args.slice(1).concat(args[0])) | |
} | |
} | |
fullName = function(name, lastName) { return name + ' ' + lastName} | |
// fullName("John", "Doe") -> "John Doe" | |
// flipArgs(fullName)("Doe", "John") -> "John Doe" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment