Skip to content

Commit

Permalink
Merge pull request #506 from brown-ccv/add-getLastTrialDataUtility
Browse files Browse the repository at this point in the history
feat: add getLastTrialData from gearshift into src/lib/utils.js
  • Loading branch information
YUUU23 authored Jul 8, 2024
2 parents c12885f + 0c43906 commit a1ba0e1
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 @@ -113,11 +113,21 @@ export function getTimeString(ms) {
}

/**
* 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 a1ba0e1

Please sign in to comment.