From 1e97ae4f9e2d61ddae8f14257133ef32dc71d024 Mon Sep 17 00:00:00 2001 From: Fabien Cazenave Date: Thu, 15 Feb 2024 22:29:04 +0100 Subject: [PATCH] code factorization --- js/dactylo.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/js/dactylo.js b/js/dactylo.js index aefcd464..654f3d8d 100644 --- a/js/dactylo.js +++ b/js/dactylo.js @@ -111,16 +111,12 @@ window.addEventListener('DOMContentLoaded', () => { const lessonFilter = word => Array.from(word).every(letter => lessonLetters.indexOf(letter) >= 0); - // gLessonLevel = level; - gLessonWords = gDictionary.words.filter(lessonFilter); - if (gLessonWords.length < MIN_WORD_COUNT) { - gLessonWords = gLessonWords.concat(gDictionary.trigrams.filter(lessonFilter)); - } - if (gLessonWords.length < MIN_WORD_COUNT) { - gLessonWords = gLessonWords.concat(gDictionary.bigrams.filter(lessonFilter)); - } - if (gLessonWords.length < MIN_WORD_COUNT) { - gLessonWords = gLessonWords.concat(rawLetters); + gLessonWords = []; + for (dict of [gDictionary.words, gDictionary.trigrams, gDictionary.bigrams, rawLetters]) { + gLessonWords = gLessonWords.concat(dict.filter(lessonFilter)); + if (gLessonWords.length > MIN_WORD_COUNT) { + break; + } } showLesson();