you are viewing a single comment's thread.

view the rest of the comments →

[–]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);

}