@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
18 lines (17 loc) • 568 B
JavaScript
import { randomString } from '../random/random-string.js';
/**
* Shuffles the positions of an array's entries (without mutating the array).
*
* @category Array
* @category Package : @augment-vir/common
* @returns A new array (does not mutate).
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export function shuffleArray(input) {
return input
.map((value) => {
return { value, sort: randomString() };
})
.sort((a, b) => a.sort.localeCompare(b.sort))
.map(({ value }) => value);
}