Skip to content

Commit

Permalink
Merge pull request #505 from brown-ccv/add-getCurrentTrialData
Browse files Browse the repository at this point in the history
feat: add getCurrentTrialData form gearshift into utils.js
  • Loading branch information
YUUU23 authored Jul 8, 2024
2 parents a1ba0e1 + 65462c5 commit 0709aec
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,28 @@ export function getTimeString(ms) {
}

/**
* Retrieves the data object from the current trial in JsPsych
* @param {JsPsych} jsPsych jsPsych instance being used to run the task
* @returns
*/
export function getCurrentTrialData(jsPsych) {
return jsPsych.getCurrentTrial().data;
}
/**
* Retrieves the data object from the last trial in JsPsych
* @param {JsPsych} jsPsych jsPsych instance being used to run the task
* @returns {Object}
*/
export function getLastTrialData(jsPsych) {
const dataCollection = jsPsych.data.getLastTrialData();
return dataCollection.trials[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 0709aec

Please sign in to comment.