From 3ac92b078b9a9e8eb33fff8e30d887a4893d75c0 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Thu, 20 Oct 2016 15:45:58 +0200 Subject: [PATCH] Replace 'arrow functions' with 'for loops' [HFP-57] --- js/questionset.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 5135d81..d8043df 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -156,23 +156,32 @@ H5P.QuestionSet = function (options, contentId, contentData) { */ 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] }); + // Shuffle the multidimensional array questionOrdering = H5P.shuffleArray(questionOrdering); - // Retrieve questions and indexes - questions = questionOrdering.map(d => d[0]); - - // Use the previous question order if it exists - var newOrder; - if (questionOrder) { - newOrder = questionOrdering.map(d => questionOrder[d[1]]); - } - else{ - newOrder = questionOrdering.map(d => d[1]); + // Retrieve question objects from the first index + var questions = []; + for (var i = 0; i < questionOrdering.length; i++) { + questions[i] = questionOrdering[i][0]; } + // Retrieve the new shuffled order from the second index + var newOrder = []; + for (var i = 0; i< questionOrdering.length; i++) { + + // Use a previous order if it exists + if(questionOrder) { + newOrder[i] = questionOrder[questionOrdering[i][1]]; + } + else { + newOrder[i] = questionOrdering[i][1]; + } + } + + // Return the questions in their new order *with* their new order return { questions:questions, questionOrder:newOrder