[go: up one dir, main page]

shufflable-array

1.0.9 • Public • Published

Shufflable-Array

Extended javascript native Array ([]) with an additional (in-place) shuffle() method

This doesn't modify Array.prototype.

npm (scoped) install size downloads
dependencies devDependencies
license Forks Stars

npm i shufflable-array

or:

yarn add shufflable-array

Usage

import ShufflableArray from 'shufflable-array'

const shufflableArray = new ShufflableArray(1, 2, 3, 4, 5)

console.log(shufflableArray instanceof Array) // => true

shufflableArray.shuffle() // => Ex. [ 5, 1, 4, 3, 2 ]

Example

import ShufflableArray from 'shufflable-array'

const shufflableArray = new ShufflableArray(1, 2, 3, 4, 5)
console.log(shufflableArray) // => ShufflableArray(5) [ 1, 2, 3, 4, 5 ]
console.log(shufflableArray[2], shufflableArray[5]) // => 3 undefined
console.log(shufflableArray.length) // => 5

shufflableArray.push(6)
console.log(shufflableArray) // => ShufflableArray(6) [ 1, 2, 3, 4, 5, 6 ]

shufflableArray[5] = 0
console.log(shufflableArray) // => ShufflableArray(6) [ 1, 2, 3, 4, 5, 0 ]

const shuffledArray = shufflableArray.shuffle()
console.log(shufflableArray) // => Ex. ShufflableArray(6) [ 1, 3, 5, 4, 0, 2 ]
console.log(shufflableArray === shuffledArray) // => true

Package Sidebar

Install

npm i shufflable-array

Weekly Downloads

1

Version

1.0.9

License

MIT

Unpacked Size

4.85 kB

Total Files

4

Last publish

Collaborators

  • mirismaili