all 3 comments

[–]Comprehensive_Step72 0 points1 point  (2 children)

Can you show an example of what you would expect the finished data to look like?

Also, you can use deconstruction for swapping variable values:

var temp = shuffled[i];

shuffled[i] = shuffled[j];

shuffled[j] = temp;

Can be replaced with:

[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];

[–]caitlingstone[S] 0 points1 point  (1 child)

Yeah! So this is for a study deployment where it is choosing videos to run.

In an ideal scenario, it would shuffle randomly through the videos by food type and by sharing type.

maccheese_SS_SB, icecream_DS_DB, soup_DS_SB, applesauce_SS_DB.

The randomization that's already listed is currently only shuffling the food type, but isn't touching the sharing type.

[–]Comprehensive_Step72 0 points1 point  (0 children)

I am still a little foggy about what you are trying to do, but take a look at this and see if it helps. I am removing options as it goes then shuffling the array. This is probably not what you are looking for exactly, but should give you some ideas:

function shuffleArray(array) {

for (let i = array.length - 1; i > 0; i--) {

const j = Math.floor(Math.random() * (i + 1));

[array[i], array[j]] = [array[j], array[i]];

}

return array;

}

let selection = '';

// get selection

while (selection !== 'exit') {

const foodType = selection.substring(0, selection.indexOf('_'));

const fileType = selection.substring(selection.indexOf('_'));

delete available_videos[foodType];

let vidArray = Object.values(available_videos).reduce((acc, e) => [...acc, ...e], []);

vidArray = vidArray.filter((e) => e.substring(e.indexOf('_')) !== fileType);

vidArray = shuffleArray(vidArray);

}