Replace 'arrow functions' with 'for loops' [HFP-57]
parent
035b958254
commit
3ac92b078b
|
@ -156,23 +156,32 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
*/
|
*/
|
||||||
var randomizeQuestionOrdering = function (questions, questionOrder) {
|
var randomizeQuestionOrdering = function (questions, questionOrder) {
|
||||||
|
|
||||||
// Save the original order of the questions in a nested array [[question0,0],[question1,1]...
|
// Save the original order of the questions in a multidimensional array [[question0,0],[question1,1]...
|
||||||
var questionOrdering = questions.map(function(object, index) { return [object, index] });
|
var questionOrdering = questions.map(function(object, index) { return [object, index] });
|
||||||
|
|
||||||
|
// Shuffle the multidimensional array
|
||||||
questionOrdering = H5P.shuffleArray(questionOrdering);
|
questionOrdering = H5P.shuffleArray(questionOrdering);
|
||||||
|
|
||||||
// Retrieve questions and indexes
|
// Retrieve question objects from the first index
|
||||||
questions = questionOrdering.map(d => d[0]);
|
var questions = [];
|
||||||
|
for (var i = 0; i < questionOrdering.length; i++) {
|
||||||
|
questions[i] = questionOrdering[i][0];
|
||||||
|
}
|
||||||
|
|
||||||
// Use the previous question order if it exists
|
// Retrieve the new shuffled order from the second index
|
||||||
var newOrder;
|
var newOrder = [];
|
||||||
|
for (var i = 0; i< questionOrdering.length; i++) {
|
||||||
|
|
||||||
|
// Use a previous order if it exists
|
||||||
if(questionOrder) {
|
if(questionOrder) {
|
||||||
newOrder = questionOrdering.map(d => questionOrder[d[1]]);
|
newOrder[i] = questionOrder[questionOrdering[i][1]];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newOrder = questionOrdering.map(d => d[1]);
|
newOrder[i] = questionOrdering[i][1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the questions in their new order *with* their new order
|
||||||
return {
|
return {
|
||||||
questions:questions,
|
questions:questions,
|
||||||
questionOrder:newOrder
|
questionOrder:newOrder
|
||||||
|
|
Loading…
Reference in New Issue