Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // take the an array and shuffle it
- function shuffleArray(array) {
- for (var i = array.length - 1; i > 0; i--) {
- var j = Math.floor(Math.random() * (i + 1));
- var temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- return array;
- }
- // push nextQuestionIndex up
- function nextQuestion() {
- nextQuestionIndex++;
- if (nextQuestionIndex >= questions.length) {
- nextQuestionIndex = 0;
- pullQuestion();
- }
- else {
- question = questions[nextQuestionIndex];
- }
- }
- //pull feed, shuffle data, write to question, set question to index 0 of shuffled data
- function pullQuestion(){
- $.ajax({
- url: "/gary/feed/",
- async: false,
- dataType: 'json',
- success: function(data) {
- shuffleArray(data); // housekeeping task
- data.splice(0, 1);
- questions = data;
- question = questions[nextQuestionIndex];
- }});
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement