@qso-soft/shared
Version:
Shared library for QSO-soft
16 lines • 643 B
JavaScript
export const shuffleArray = (array) => {
const shuffledArray = [...array];
const minArrayLengthToShuffle = 2;
if (array.length >= minArrayLengthToShuffle) {
for (let i = array.length - 1; i > 0; i--) {
const randomIndex = Math.floor(Math.random() * (i + 1));
const indexElement = shuffledArray[i];
const randomElement = shuffledArray[randomIndex];
if (indexElement && randomElement) {
[shuffledArray[i], shuffledArray[randomIndex]] = [randomElement, indexElement];
}
}
}
return shuffledArray;
};
//# sourceMappingURL=shuffle.js.map