Category
Array to shuffle
Optional
mutate: trueOptional, true
if specified
const array = [1, 2, 3];
shuffle(array);
sample if you only want to select one element at random
Array
Category
A non-mutating uniformly random array shuffle.
Time complexity: O(n)
Space complexity: O(n)
The shuffled array
Array
const array = [1, 2, 3];
const shuffled = shuffle(array, false);
sample if you only want to select one element at random
A mutating (in-place) uniformly random array shuffle.
Time complexity: O(n)
Space complexity: O(1)