correct badWords list and simplify word list trimming
authorLaurent Mazet <mazet@softndesign.org>
Sat, 20 Jun 2020 21:35:45 +0000 (23:35 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sat, 20 Jun 2020 21:35:45 +0000 (23:35 +0200)
public/trivabble.js

index a4bf6ba9bc227d102104c00413fb29461b9effcd..2e4888d08e865c17ca2bb2209cde66f60cf63ce5 100644 (file)
             setTimeout(function () {highlightWord(newWords[k], "tile-spelling-ok", false);}, 5000);
             const pattern = "^" + newWords[k].letters.replace(/ /g, ".") + "$";
             if (!dictionary.find(element => element.match(pattern))) {
-                badWords.push(newWords[k]);
+                badWords.push(newWords[k].letters.replace(/ /g, "?"));
                 highlightWord(newWords[k], "tile-spelling-nok", true);
                 setTimeout(function () {highlightWord(newWords[k], "tile-spelling-nok", false);}, 5000);
             }
         }
-        words = words.join(", ")
-            .replace(/^ */u, "")
-            .replace(/ *$/u, "");
-        badWords = badWords.join(", ")
-            .replace(/^ */u, "")
-            .replace(/ *$/u, "");
+        words = words.join(", ").trim();
+        badWords = badWords.join(", ").trim();
 
         /* Advice on erroneous spelling */
         if (badWords.length > 0) {