diff --git a/src/backend/utils/evaluations/pullMetaculusForecastsToCSVForRating.ts b/src/backend/utils/evaluations/pullMetaculusForecastsToCSVForRating.ts index 0076f67..6cc2231 100644 --- a/src/backend/utils/evaluations/pullMetaculusForecastsToCSVForRating.ts +++ b/src/backend/utils/evaluations/pullMetaculusForecastsToCSVForRating.ts @@ -1,6 +1,7 @@ /* Imports */ import fs from "fs"; +import { shuffleArray } from "../../../utils"; import { pgRead } from "../../database/pg-wrapper"; /* Definitions */ @@ -13,15 +14,6 @@ let getQualityIndicators = (question) => .map((entry) => `${entry[0]}: ${entry[1]}`) .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 */ let main = async () => { diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..649b2a7 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,8 @@ +export const shuffleArray = (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; +};