From f55c5650ffac1781c1cd675f64276c4e4c33d2b8 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 12 Jun 2020 10:10:06 -0700 Subject: [PATCH] Fix bug with incorrect scoring based on capitalization As exposed in the previous commit which extended testing. After we construct what we call "word maps", (where a group of words are hased to by each word in the group individually), we collapse them down to just the array of word groups themselves. This step was being carried out by looking for the mapping to the word group where the mapped word matched the first word in the list. However, if that first word happened to differ in case from the mapping word (which was already made canonically lowercase) then the word group wouldn't be included in the final array and all submissions of words from that group would incorrectly be scored as singletons. The fix for this is to simply force the word being compared to as in this commit. This commit causes the test suite to pass again. --- empathy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/empathy.js b/empathy.js index 759b486..e80c1af 100644 --- a/empathy.js +++ b/empathy.js @@ -266,7 +266,8 @@ class Empathy extends Game { * multiple times). In contrast, iterating over"word_groups" will * have you visit each group only once. */ const word_groups = Object.entries(word_maps).filter( - entry => entry[0] === entry[1].words[0]).map(entry => entry[1]); + entry => entry[0] === this.canonize(entry[1].words[0])) + .map(entry => entry[1]); /* Now, go through each word group and assign the scores out to * the corresponding players. -- 2.43.0