Skip to content

Commit

Permalink
feat: from gearshift, move in getRandomElement function into src/lib/…
Browse files Browse the repository at this point in the history
…utils.js
  • Loading branch information
YUUU23 committed Jul 6, 2024
1 parent 890de74 commit bfce4cb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

0 comments on commit bfce4cb

Please sign in to comment.