Skip to content

Instantly share code, notes, and snippets.

@edtsech
Last active November 7, 2016 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edtsech/8fc3145f8ff47689b96e50dfe6cf995e to your computer and use it in GitHub Desktop.
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.
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