Shuffles an input array and returns a copy of it. Uses the modern Fisher-Yates shuffle algorithm to generate a random permutation of the input array.
The input array is not modified.
shuffle(['foo', 'bar', 'baz'])// => { ok: true, value: shuffled copy of the array } Copy
shuffle(['foo', 'bar', 'baz'])// => { ok: true, value: shuffled copy of the array }
Handle an invalid input:
shuffle('not an array')// => { ok: false, value: error: Error('[collections.shuffle] Input is not an array') } Copy
shuffle('not an array')// => { ok: false, value: error: Error('[collections.shuffle] Input is not an array') }
The type of the elements in the array.
The array to shuffle.
A Result object with either the shuffled array if ok, or an Error object if the provided input is not an array
ok
Error
Generated using TypeDoc v0.24.7
Shuffles an input array and returns a copy of it. Uses the modern Fisher-Yates shuffle algorithm to generate a random permutation of the input array.
Remarks
The input array is not modified.
Example
Example
Handle an invalid input: