This code should choose one value from the array and then execute according to that value. Instead, the code selects multiples from the array and then iterates through the else if multiple times.
Here is the first case of the switch with the issues:
switch (autoshuffle) {
case "random":
autoshuffle = ["true", "false", "ascending", "descending"][
Math.floor(Math.random() * 4)
];
console.log(autoshuffle);
if (autoshuffle == "true") {
shufflexup(file_list);
console.log("sort shuffled");
} else if (autoshuffle == "ascending") {
file_list.sort();
console.log("sort ascending");
} else if (autoshuffle == "descending") {
file_list.sort();
file_list.reverse();
console.log("sort descending");
}
break;
}
Here are some console results:
Run 1
true
false
ascending
sort ascending
Run 2
ascending
sort ascending
descending
sort descending
descending
sort descending
Due to this multiple unwanted sorts are occurring and impacting performance.
I tried adding an ending else, but it made no difference.
Certain I'm doing something stupid. Appreciate any insights.