Getting different lists from a file that contains all stimuli #2768
-
Hi there! I am looking for a way to define the lists automatically by some kind of function. For my stimuli, I have a js file that contains all the stimuli for all the lists (called stimuli_all.js), and the entries look something like this (there are 8 lists in total): {
list: "1",
set: "coffee",
condition: "C",
img: "coffee_s1.jpg"
},
{
list: "2",
set: "coffee",
condition: "A",
img: "coffee_s2.jpg"
}, I would like to write code that says something like "if list ==1, add this stimulus to stimuli_list_1" etc, instead of manually creating 8 different files from my full file. So far, I have tried to do it like this: // assign subject randomly to 1 out of 8 lists
var list_assignment = jsPsych.randomization.sampleWithoutReplacement([1,2,3,4,5,6,7,8], 1)[0];
// add list information to data
jsPsych.data.addProperties({
condition: list_assignment
});
// assign only those stimuli to the list that correspond to the assigned list
var stimuli_list = stimuli_all.filter(x => x.list == list_assignment) At first glance it seems to work, but as I'm new to programming and have never taken a course, I'm not sure if there aren't some hidden pitfalls and there might be a better solution. Thanks a lot in advance for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't see anything wrong with this approach. What I would do personally is organize the js file so that the different lists are in there explicitly: you define a key for the list number and for each list number you define the array of stimuli that corresponds to it. But I guess that's just an alternative way of doing things :)
|
Beta Was this translation helpful? Give feedback.
I don't see anything wrong with this approach. What I would do personally is organize the js file so that the different lists are in there explicitly: you define a key for the list number and for each list number you define the array of stimuli that corresponds to it. But I guess that's just an alternative way of doing things :)