MCPcopy Create free account
hub / github.com/Levofron/NotionLingo / shuffleArray

Function shuffleArray

server/utils/shuffle-array/shuffle-array.function.ts:3–15  ·  view source on GitHub ↗
(array: T[])

Source from the content-addressed store, hash-verified

1import { getRandomNumber } from '../get-random-number/get-random-number.function';
2
3export const shuffleArray = <T>(array: T[]) => {
4 const copiedArray = [...array];
5
6 for (let i = copiedArray.length - 1; i > 0; i -= 1) {
7 const j = getRandomNumber(0, i + 1);
8 const temp = copiedArray[i];
9
10 copiedArray[i] = copiedArray[j];
11 copiedArray[j] = temp;
12 }
13
14 return copiedArray;
15};

Callers 1

Calls 1

getRandomNumberFunction · 0.90

Tested by

no test coverage detected