refactor(api, curriculum): use the shared shuffleArray util (#56444)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Huyen Nguyen
2024-10-02 06:55:38 -07:00
committed by GitHub
parent 52ea949997
commit 0ba9eeff43
4 changed files with 8 additions and 42 deletions
+1 -17
View File
@@ -1,23 +1,7 @@
import { Exam, Question } from '@prisma/client';
import { shuffleArray } from './../../../shared/utils/shuffle-array';
import { UserExam, GeneratedExam } from './exam-types';
function shuffleArray<T>(arr: T[]): T[] {
let currentIndex: number = arr.length;
let randomIndex: number;
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[arr[currentIndex], arr[randomIndex]] = [
arr[randomIndex] as T,
arr[currentIndex] as T
];
}
return arr;
}
/**
* Remove objects from array with deprecated: true.
*