refactor: extract shuffleArray to src/utils
This commit is contained in:
parent
4da6e08448
commit
71ab64343f
|
@ -1,6 +1,7 @@
|
||||||
/* Imports */
|
/* Imports */
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
|
import { shuffleArray } from "../../../utils";
|
||||||
import { pgRead } from "../../database/pg-wrapper";
|
import { pgRead } from "../../database/pg-wrapper";
|
||||||
|
|
||||||
/* Definitions */
|
/* Definitions */
|
||||||
|
@ -13,15 +14,6 @@ let getQualityIndicators = (question) =>
|
||||||
.map((entry) => `${entry[0]}: ${entry[1]}`)
|
.map((entry) => `${entry[0]}: ${entry[1]}`)
|
||||||
.join("; ");
|
.join("; ");
|
||||||
|
|
||||||
let shuffleArray = (array) => {
|
|
||||||
// See: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
|
||||||
for (let i = array.length - 1; i > 0; i--) {
|
|
||||||
const j = Math.floor(Math.random() * (i + 1));
|
|
||||||
[array[i], array[j]] = [array[j], array[i]];
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Body */
|
/* Body */
|
||||||
|
|
||||||
let main = async () => {
|
let main = async () => {
|
||||||
|
|
8
src/utils.ts
Normal file
8
src/utils.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
export const shuffleArray = <T>(array: T[]): T[] => {
|
||||||
|
// See: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
||||||
|
for (let i = array.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[array[i], array[j]] = [array[j], array[i]];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user