1.0.1 • Published 7 years ago

shuffle-array v1.0.1

Weekly downloads
46,635
License
MIT
Repository
github
Last release
7 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-2756orikaeshi-frontourtunesolebeh-blackjackpeernetpeer-array-sepl2htmlpolyfill-service@generative-music/piece-pinwheelswhitelabel-dbwhitehall@gnarula/cothority@gonation/theme-gntvcodeforces-cli@marionebl/polyfill-libraryfonts-similarizerreact-music-playerreact-tagcloudrbs-timezonerbl-fingerprintsrandom-open-colorpurge-usersproxy-rotator-uploaderproxy-balancerrandom-sortreddit-djsreddit-image-fetcherrich-baccaratqwalletscatter-chart-simpleshardy-mc-shard-faceshuffle-obj-arraysshuffledsonotmold-blacjackstring_transformersimple-human-idssimple-proxiessitemap_utilss2wsseneca-loadbalance-transportscsynthsudoku-generatortypescript_quiz-using-inquirer-and-chalkvadimtk1-arrayvante-blackjackvehikl-memory-game-packageweighted-screenwsanalyzer@l-v-yonsama/multi-platform-database-driversdowding@louismerlin/cothoritycovfefecosync-node-cosyncctx-defensedaisy-blackjackglad-nnglob-playlistgame-plusgreatapticflike@mtnpay/sdkga-tspdonddiscord-blackjackdiscord-blackjack-trdiscord-blackjack-v14discord-blackjack-vietnamirasutoyercompare-fonts@jam-comments/utilitiescustom-bj@jeannechaverot/cothoritydemba-ba-netguess_num_tjs-basic-utils@ericlai616/reviewer-assignment-botjelly-djs@sithusoe/baccarat-enginehomebridge-dmxlight-plugin@turel/discord-blackjackline-chart-simplelibtrislubyluxafor-for-slackkuhhandelmajorsystemmachi-koro-game@team-chatt/solitairematchmocy-blackjackaurora-demo-api@c4dt/cothoritynfw-core
1.0.1

7 years ago

1.0.0

8 years ago

0.0.1-security

8 years ago

2.0.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

9 years ago

0.0.2

10 years ago

0.0.0

10 years ago