added difficulty
This commit is contained in:
@@ -16,30 +16,30 @@ const kanas = {
|
|||||||
'(N)',
|
'(N)',
|
||||||
],
|
],
|
||||||
hiraganas: [
|
hiraganas: [
|
||||||
[ 'あ', 'い', 'う', 'え', 'お' ],
|
'あいうえお',
|
||||||
[ 'か', 'き', 'く', 'け', 'こ' ],
|
'かきくけこ',
|
||||||
[ 'さ', 'し', 'す', 'せ', 'そ' ],
|
'さしすせそ',
|
||||||
[ 'た', 'ち', 'つ', 'て', 'と' ],
|
'たちつてと',
|
||||||
[ 'な', 'に', 'ぬ', 'ね', 'の' ],
|
'なにぬねの',
|
||||||
[ 'は', 'ひ', 'ふ', 'へ', 'ほ' ],
|
'はひふへほ',
|
||||||
[ 'ま', 'み', 'む', 'め', 'も' ],
|
'まみむめも',
|
||||||
[ 'や', '', 'ゆ', '', 'よ' ],
|
'や ゆ よ',
|
||||||
[ 'ら', 'り', 'る', 'れ', 'ろ' ],
|
'らりるれろ',
|
||||||
[ 'わ', '', '', '', 'を' ],
|
'わ を',
|
||||||
[ 'ん' ],
|
'ん',
|
||||||
],
|
],
|
||||||
katakanas: [
|
katakanas: [
|
||||||
[ 'ア', 'イ', 'ウ', 'エ', 'オ' ],
|
'アイウエオ',
|
||||||
[ 'カ', 'キ', 'ク', 'ケ', 'コ' ],
|
'カキクケコ',
|
||||||
[ 'サ', 'シ', 'ス', 'セ', 'ソ' ],
|
'サシスセソ',
|
||||||
[ 'タ', 'チ', 'ツ', 'テ', 'ト' ],
|
'タチツテト',
|
||||||
[ 'ナ', 'ニ', 'ヌ', 'ネ', 'ノ' ],
|
'ナニヌネノ',
|
||||||
[ 'ハ', 'ヒ', 'フ', 'ヘ', 'ホ' ],
|
'ハヒフヘホ',
|
||||||
[ 'マ', 'ミ', 'ム', 'メ', 'モ' ],
|
'マミムメモ',
|
||||||
[ 'ヤ', '', 'ユ', '', 'ヨ' ],
|
'ヤ ユ ヨ',
|
||||||
[ 'ラ', 'リ', 'ル', 'レ', 'ロ' ],
|
'ラリルレロ',
|
||||||
[ 'ワ', '', '', '', 'ヲ' ],
|
'ワ ヲ',
|
||||||
[ 'ン' ],
|
'ン',
|
||||||
],
|
],
|
||||||
exceptions: {
|
exceptions: {
|
||||||
SI: 'SHI',
|
SI: 'SHI',
|
||||||
@@ -48,12 +48,21 @@ const kanas = {
|
|||||||
HU: 'FU',
|
HU: 'FU',
|
||||||
},
|
},
|
||||||
traps: {
|
traps: {
|
||||||
hiraganas: {
|
hiraganas: [
|
||||||
//TODO
|
'うえふら',
|
||||||
},
|
'いりにけはほ',
|
||||||
katakanas: {
|
'あおぬめ',
|
||||||
//TODO
|
'れねわ',
|
||||||
},
|
'しも',
|
||||||
|
'つてと',
|
||||||
|
'るろそ',
|
||||||
|
'まはほよ',
|
||||||
|
'くへ',
|
||||||
|
'たなを',
|
||||||
|
'えん',
|
||||||
|
'きさち',
|
||||||
|
],
|
||||||
|
katakanas: [],
|
||||||
},
|
},
|
||||||
mappings: [
|
mappings: [
|
||||||
[ 0, 1 ],
|
[ 0, 1 ],
|
||||||
@@ -79,22 +88,24 @@ const utils = {
|
|||||||
} while (this.contains(toIgnore, index));
|
} while (this.contains(toIgnore, index));
|
||||||
return index;
|
return index;
|
||||||
},
|
},
|
||||||
randitem: function (array) {
|
randitem: function (array, ...toIgnore) {
|
||||||
if (array.length === 0) {
|
if (array.length === 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return array[this.randindex(array)];
|
return array[this.randindex(array, ...toIgnore)];
|
||||||
},
|
},
|
||||||
randindexes: function (array, number, ...toIgnore) {
|
randindexes: function (array, number, ...toIgnore) {
|
||||||
if (array.length === 0 || toIgnore.length >= array.length) {
|
number = Math.min(number, array.length - toIgnore.length);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const output = [];
|
const output = [];
|
||||||
for (let i = 0; i < number; i++) {
|
for (let i = 0; i < number; i++) {
|
||||||
output.push(this.randindex(array, ...output, ...toIgnore));
|
output.push(this.randindex(array, ...output, ...toIgnore));
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
randitems: function (array, number) {
|
||||||
|
const indexes = this.randindexes(array, number);
|
||||||
|
return indexes.map(i => array[i]);
|
||||||
|
},
|
||||||
shuffle: function (array) {
|
shuffle: function (array) {
|
||||||
const output = [ ...array ];
|
const output = [ ...array ];
|
||||||
for (let i = 0; i < array.length; i++) {
|
for (let i = 0; i < array.length; i++) {
|
||||||
@@ -107,6 +118,9 @@ const utils = {
|
|||||||
contains: function (array, item) {
|
contains: function (array, item) {
|
||||||
return array.indexOf(item) >= 0;
|
return array.indexOf(item) >= 0;
|
||||||
},
|
},
|
||||||
|
unique: function (array) {
|
||||||
|
return [ ...new Set(array) ];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.shuffle = function () {
|
Array.prototype.shuffle = function () {
|
||||||
@@ -115,6 +129,9 @@ Array.prototype.shuffle = function () {
|
|||||||
Array.prototype.contains = function (item) {
|
Array.prototype.contains = function (item) {
|
||||||
return utils.contains(this, item);
|
return utils.contains(this, item);
|
||||||
};
|
};
|
||||||
|
Array.prototype.unique = function () {
|
||||||
|
return utils.unique(this);
|
||||||
|
};
|
||||||
|
|
||||||
let app = {
|
let app = {
|
||||||
el: '#app',
|
el: '#app',
|
||||||
@@ -158,7 +175,7 @@ let app = {
|
|||||||
const text = kanas.exceptions[prefix + suffix]
|
const text = kanas.exceptions[prefix + suffix]
|
||||||
? kanas.exceptions[prefix + suffix]
|
? kanas.exceptions[prefix + suffix]
|
||||||
: prefix + suffix;
|
: prefix + suffix;
|
||||||
if (kanas.hiraganas[row][column] || kanas.katakanas[row][column]) {
|
if (kanas.hiraganas[row][column] !== ' ') {
|
||||||
self.kanas.push([ text, kanas.hiraganas[row][column], kanas.katakanas[row][column], row, column ]);
|
self.kanas.push([ text, kanas.hiraganas[row][column], kanas.katakanas[row][column], row, column ]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -169,18 +186,19 @@ let app = {
|
|||||||
const self = this;
|
const self = this;
|
||||||
const kana = self.kanas[kanaIndex];
|
const kana = self.kanas[kanaIndex];
|
||||||
const similarIndexes = [];
|
const similarIndexes = [];
|
||||||
if (mapping.contains(1) && kanas.traps.hiraganas[kana[1]]) {
|
if (mapping.contains(1)) {
|
||||||
const trap = self.findKana(utils.randitem(kanas.traps.hiraganas[kana[1]]));
|
const traps = kanas.traps.hiraganas.filter(line => line.includes(kana[1]));
|
||||||
const trapIndex = self.kanas.indexOf(trap);
|
utils.randitems(traps, 2).forEach(line => {
|
||||||
similarIndexes.push(trapIndex);
|
const trapKana = utils.randitem(line.split(''), line.indexOf(kana[1]));
|
||||||
|
similarIndexes.push(self.kanas.indexOf(self.findKana(trapKana)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (mapping.contains(2) && kanas.traps.katakanas[kana[2]]) {
|
if (mapping.contains(2)) {
|
||||||
const trap = self.findKana(utils.randitem(kanas.traps.hiraganas[kana[1]]));
|
const traps = kanas.traps.katakanas.filter(line => line.includes(kana[2]));
|
||||||
const trapIndex = self.kanas.indexOf(trap);
|
utils.randitems(traps, 2).forEach(line => {
|
||||||
|
const trapKana = utils.randitem(line.split(''), line.indexOf(kana[2]));
|
||||||
if (!similarIndexes.contains(trapIndex)) {
|
similarIndexes.push(self.kanas.indexOf(self.findKana(trapKana)));
|
||||||
similarIndexes.push(self.kanas.indexOf(trap));
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (kana[0].length !== 1 || kana[0] !== 'N') {
|
if (kana[0].length !== 1 || kana[0] !== 'N') {
|
||||||
const sameRow = self.kanas.filter((kana2, i) => !similarIndexes.contains(i) && kana2 !== kana && kana2[3] === kana[3]);
|
const sameRow = self.kanas.filter((kana2, i) => !similarIndexes.contains(i) && kana2 !== kana && kana2[3] === kana[3]);
|
||||||
@@ -192,7 +210,7 @@ let app = {
|
|||||||
similarIndexes.push(self.kanas.indexOf(utils.randitem(sameColumn)));
|
similarIndexes.push(self.kanas.indexOf(utils.randitem(sameColumn)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return similarIndexes;
|
return similarIndexes.unique();
|
||||||
},
|
},
|
||||||
generateQuestion: function () {
|
generateQuestion: function () {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|||||||
Reference in New Issue
Block a user