fisher-yates
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

fisher-yates

A compact module to randomly sort an Array.

Usage

const shuffle = require('fisher-yates')

console.log(shuffle([1, 2, 3]))
// => [3, 1, 2]

// supports custom rng returning [0, 1)
console.log(shuffle([1, 2, 3], Math.random))
// => [2, 3, 1]

For shuffling your array in-place, use fisher-yates/inplace

const shuffleInplace = require('fisher-yates/inplace')
const array = [1, 2, 3]

shuffleInplace(array)
console.log(array)
// => [2, 1, 3]

LICENSE MIT

Package Sidebar

Install

npm i fisher-yates

Weekly Downloads

420

Version

1.0.4

License

MIT

Unpacked Size

4.18 kB

Total Files

8

Last publish

Collaborators

  • dcousens