Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including shuffler with all npm packages installed. Try it out:

var shuffler = require("shuffler")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

shuffler v0.0.1

Allows you to swap around the order of a function's arguments by index.

shuffler Build Status

shuffler lets you swap around the order of a function's arguments by index.


Using NPM:

$ npm install shuffler

Or as a component:

$ component install hughsk/shuffler


shuffler takes a function as its first argument and returns a second function to determine the new argument order. Take this example:

var shuffle = require('shuffler')

function args() {

args('a', 'b', 'c', 'd') // ['a', 'b', 'c', 'd']

args = shuffle(args)(3, 2, 1, 0)
args('a', 'b', 'c', 'd') // ['d', 'c', 'b', 'a']

You can pass a falsey non-numerical value to mute it, i.e. that argument will always be null:

args('a', 'b', 'c', 'd') // ['a', 'b', 'c', 'd']

args = shuffle(args)(3, 2, false, 0)
args('a', 'b', 'c', 'd') // ['d', 'c', null, 'a']

Or a truthy non-numerical value to just use the default argument:

args('a', 'b', 'c', 'd') // ['a', 'b', 'c', 'd']

args = shuffle(args)(3, 2, true, 3)
args('a', 'b', 'c', 'd') // ['d', 'c', 'c', 'd']

By default, any extra arguments will still be used. You can disable this by passing the carryon option as false.

args('a', 'b', 'c', 'd') // ['a', 'b', 'c', 'd']

args = shuffle(args)(1, 1)
args('a', 'b', 'c', 'd') // ['b', 'b', 'c', 'd']

args = shuffle(args, { carryon: false })(1, 1)
args('a', 'b', 'c', 'd') // ['b', 'b']


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free