1.0.1 • Published 8 years ago

shuffle-array v1.0.1

Weekly downloads
46,635
License
MIT
Repository
github
Last release
8 years ago

shuffle-array

NPM version License Build status Coverage Status devDependency status downloads

Randomize the order of the elements in a given array using the Fisher-Yates algorithm.

Installation

$ npm install shuffle-array

$ bower install shuffle-array

$ component install pazguille/shuffle-array

Usage

var shuffle = require('shuffle-array'),
    collection = [1,2,3,4,5];

shuffle(collection);

console.log(collection); // returns [4, 3, 1, 5, 2]

API

shuffle(arr, options)

Randomizes the order of the elements in a given array.

  • arr - The given array.
  • options {Object} - Optional configuration options.
  • options.copy {Boolean} - Sets if should return a shuffled copy of the given array. By default it's a falsy value.
  • options.rng {Function} - Specifies a custom random number generator.
shuffle([1,2,3,4,5]); // returns [4, 3, 1, 5, 2]

// Return a copy of the given array
shuffle([1,2,3,4,5], { 'copy': true }); // returns [4, 3, 1, 5, 2] (copied)

shuffle.pick(arr, options)

Pick one or more random elements from the given array.

  • arr - The given array.
  • options {Object} - Optional configuration options.
  • options.picks {Number} - Specifies how many random elements you want to pick. By default it picks 1.
  • options.rng {Function} - Specifies a custom random number generator.
shuffle.pick([1,2,3,4,5]); // returns 5

// Return a random collection with 2 elements
shuffle.pick([1,2,3,4,5], { 'picks': 2 })); // returns [4, 3]

Build

npm run dist

Test

npm test

With :heart: by

License

MIT license. Copyright © 2014.

youtube-bookmarks-playerrandom-image-jssync-car-adlubyjs@enaviga/client-componentsnsfw-helpers@infinitebrahmanuniverse/nolb-shu@everything-registry/sub-chunk-2756discord-blackjack-v14whitehallwhitelabel-dbweighted-screenwsanalyzervehikl-memory-game-packagevadimtk1-arrayvante-blackjackaurora-demo-apijelly-djsirasutoyerjs-basic-utilsjumbledolebeh-blackjacksudoku-generatorstring_transformersonotmold-blacjacktypescript_quiz-using-inquirer-and-chalk@c4dt/cothority@dedis/cothority@gonation/theme-gntv@generative-music/piece-pinwheels@gnarula/cothority@louismerlin/cothority@mtnpay/sdk@marionebl/polyfill-library@ericlai616/reviewer-assignment-bot@jam-comments/utilities@jeannechaverot/cothority@sithusoe/baccarat-enginemocy-blackjackorikaeshi-frontpeernetourtunesreact-music-playerscatter-chart-simplescsynthrbs-timezones2wsseneca-loadbalance-transportnfw-corepl2htmlpeer-array-sepolyfill-servicerich-baccaratproxy-balancerpurge-usersrandom-sortrandom-open-colorqwalletreddit-image-fetcherreddit-djsproxy-rotator-uploaderrbl-fingerprintssimple-human-idssimple-proxiesreact-tagcloudsitemap_utilsshardy-mc-shard-faceshuffle-obj-arraysshuffledglob-playlistglad-nnhomebridge-dmxlight-pluginguess_num_tgreatapticlibtrisline-chart-simplelubymachi-koro-gameluxafor-for-slackmajorsystemkuhhandelmatch@turel/discord-blackjack@team-chatt/solitairebaccarat-engineaprendercompare-fontscli-qcmcodeforces-clicosync-node-cosynccovfefedaisy-blackjackcustom-bjctx-defensedemba-ba-netbeer-mebingo.jsbyebytebridge-enginediscord-blackjack
1.0.1

8 years ago

1.0.0

9 years ago

0.0.1-security

9 years ago

2.0.0

9 years ago

0.1.2

9 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.2

11 years ago

0.0.0

11 years ago