From bfce4cbf9e4ecb8cd70532d9281d9ef8856ecff3 Mon Sep 17 00:00:00 2001 From: YUUU23 Date: Sat, 6 Jul 2024 13:55:44 -0500 Subject: [PATCH] feat: from gearshift, move in getRandomElement function into src/lib/utils.js --- src/lib/utils.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/utils.js b/src/lib/utils.js index d5a58392c..d0d3f78ae 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -111,3 +111,13 @@ export function getSeconds(ms) { export function getTimeString(ms) { return `${getMinute(ms)}:${getSeconds(ms).toString().padStart(2, "0")}`; } + +/** + * Randomly retrieves a single element from an array + * @param {JsPsych} jsPsych The jsPsych instance being used to run the task + * @param {Array} array A given array of elements + * @returns + */ +export function getRandomElement(jsPsych, array) { + return jsPsych.randomization.sampleWithoutReplacement(array, 1)[0]; +}