Underscore.JS - shuffle method



Syntax

_.shuffle(list)

shuffle method shuffles the given list using Fisher-Yates shuffle algorithm.

Example

var _ = require('underscore');

//Example: shuffle a list of numbers
result = _.shuffle([1, 2, 3, 4, 5, 6])
console.log(result)

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 1, 5, 3, 4, 2, 6 ]
underscorejs_processing_collection.htm
Advertisements