@outbook/shuffle
v1.0.2
Published
Returns a new array with its elements shuffled using the Fisher–Yates algorithm
Downloads
10
Readme
@outbook/shuffle
Returns a new array with its elements shuffled using the Fisher-Yates algorithm.
Install
npm install @outbook/shuffleUsage
import { shuffle } from '@outbook/shuffle';
const original = ['a', 'b', 'c', 'd'];
const result = shuffle(original);
console.log(result);
// Example: ['c', 'a', 'd', 'b']
console.log(original);
// ['a', 'b', 'c', 'd']API
shuffle(source)
Returns a shuffled copy of source.
source:Arrayto shuffle.- Returns: a new
Arraycontaining the same elements in random order.
Behavior:
- Does not mutate the original array.
- Uses a shallow copy of the input array.
- Works well for common application-level randomization where
Math.random()is acceptable.
Notes
- The package exposes a named
shuffleexport. - Shuffling is random, so output order will vary between calls.
Development
Source files live in src/. The public entry point is index.js.
