Skip to content

Instantly share code, notes, and snippets.

@edtsech

edtsech/flipArgs.js

Last active Nov 7, 2016
Embed
What would you like to do?
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