word/quiz: common js function to shuffle arrays
[sheet.git] / word / quiz.js
1 Array.prototype.shuffle = function () {
2         return this.sort(() => {return .5 - Math.random()});
3 };
4
5 class WordQuiz {
6         dataselect(json) {
7                 let rows = Object.values(json);
8                 return rows.shuffle();
9         }
10
11         load(dataurl) {
12                 fetch(dataurl).then(res => res.json()).then(json => {
13                         this.words = this.dataselect(json)
14                         this.setup();
15                 });
16         }
17
18         constructor(dataurl) {
19                 this.load(dataurl);
20         }
21 }