0.4.0 • Published 7 years ago

array-shuffle-fp v0.4.0

Weekly downloads
3
License
GPL-2.0+
Repository
github
Last release
7 years ago

array-shuffle-fp Build Status npm version

Randomize the order of items in an array using FP style.

Uses the modern version of the Fisher–Yates algorithm:

-- To shuffle an array a of n elements (indices 0..n-1):
for i from n−1 downto 1 do
     j ← random integer such that 0 ≤ j ≤ i
     exchange a[j] and a[i]

Install

$ npm install --save array-shuffle-fp

Usage

const arrayShuffle = require( 'array-shuffle-fp' );

const result = arrayShuffle( [ 'a', 'b', 'c', 'd', 'e' ] );

console.log( result ); // [ 'c', 'e', 'a', 'd', 'b' ]

Test

$ npm test

Support

Node.js 6+.

License

array-shuffle-fp is licensed under GNU General Public License v2 (or later).