mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(api, curriculum): use the shared shuffleArray util (#56444)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
+1
-17
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user