All files / server/src/utils shuffleArray.ts

88.88% Statements 8/9
100% Branches 0/0
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 1339x   3x   3x 1256x 1256x 1256x 1256x   3x    
export const shuffleArray = <T>(array: readonly T[]): readonly T[] => {
  // Don't mutate input array
  const shuffledArray = [...array];
 
  for (let i = shuffledArray.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    const temp = shuffledArray[i];
    shuffledArray[i] = shuffledArray[j];
    shuffledArray[j] = temp;
  }
  return shuffledArray;
};