From 52a858a4a24b19d14619ea21ee06540f9fe3942a Mon Sep 17 00:00:00 2001 From: vonBarbarosa Date: Sun, 21 Feb 2016 17:54:41 -0300 Subject: [PATCH] Randomize words DB --- js/functions.js | 2 +- js/wordsDB.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/js/functions.js b/js/functions.js index ca63d9c..f6ca4f8 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1,5 +1,5 @@ var currentWord = { - index: 2, + index: -1, ortography: "", phonology: [], alternative: [], diff --git a/js/wordsDB.js b/js/wordsDB.js index febd46e..720a859 100644 --- a/js/wordsDB.js +++ b/js/wordsDB.js @@ -1,3 +1,14 @@ +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; +} + + var wordsDB = [ { //agora a.ˈgɔ.rə @@ -36,3 +47,5 @@ var wordsDB = [ phonology : ["ˈdeʊ̯s","ˈdeʊ̯ʃ"] } ]; + +shuffleArray(wordsDB);