After randomizing an array of question elements I am trying to save the new indexes of the elements.
I use an array called idMap to do achieve this. It saves the original index in the first for loop then updates the index once the question elements array has been shuffled.
Is there better way to do this without saving the order as an attribute of the question (questionInstances[i].originalOrder) as it may be overwritten?
// Save the original order of array
for (var i = 0; i < questionInstances.length; i++) {
questionInstances[i].originalOrder = i;
idMap[i] = i;
}
// Randomize array
if (params.randomQuestions) {
questionInstances = H5P.shuffleArray(questionInstances);
// Save new randomized order
for (var i = 0; i < questionInstances.length; i++) {
idMap[i] = questionInstances[i].originalOrder;
}
}