Conversation
nancy-harris
left a comment
There was a problem hiding this comment.
Excellent job! There are some comments below on places to make the code cleaner/simpler. For commits, it would be great if the commit messages could be more descriptive. Instead of talking about what tests are passing, something like "Added drawLetters function" would be great. Good job!
| const correct = { word: "XXXX", score: scoreWord("XXXX") }; | ||
|
|
||
| throw "Complete test by adding an assertion"; | ||
| expect(highestScoreFrom(words)).toEqual(correct); |
| expectScores({ | ||
| "": 0, | ||
| }); |
| @@ -1,15 +1,122 @@ | |||
| const letterDist = { | |||
| Z: 1, | ||
| }; | ||
|
|
||
| export const drawLetters = () => { |
| for (let letter of input) { | ||
| if (lettersInHand.includes(letter)) { | ||
| let i = lettersInHand.indexOf(letter); | ||
| lettersInHand.splice(i, 1); |
There was a problem hiding this comment.
We should not be removing letters from the lettersInHand array. This function should just be checking to make sure all of the letters in input is in lettersInHand. If the user is losing letters every time we do this check, there will be no hand left soon.
| let letterScore = {}; | ||
| const buildScoreDict = (letters, score) => { | ||
| for (const letter of letters) { | ||
| letterScore[letter] = score; | ||
| } | ||
| }; | ||
|
|
||
| buildScoreDict(["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], 1); | ||
| buildScoreDict(["D", "G"], 2); | ||
| buildScoreDict(["B", "C", "M", "P"], 3); | ||
| buildScoreDict(["F", "H", "V", "W", "Y"], 4); | ||
| buildScoreDict(["K"], 5); | ||
| buildScoreDict(["J", "X"], 8); | ||
| buildScoreDict(["Q", "Z"], 10); |
There was a problem hiding this comment.
This can be done by just creating the object like you do with the letterDist.
| word = word.toUpperCase(); | ||
|
|
||
| let points = 0; | ||
| if (word.length === 0) { | ||
| return points; | ||
| } else if (word.length > 6) { | ||
| points += 8; | ||
| } | ||
| for (let letter of word) { | ||
| points += letterScore[letter]; | ||
| } | ||
| return points; |
| // Implement this method for wave 4 | ||
| let max = 0; | ||
| let highestScoreWord = ""; | ||
| for (let word of words) { |
There was a problem hiding this comment.
Instead of calling scoreWord multiple times, it would be more efficient to call it once at the beginning of the for loop and store it in a variable.
| } else if (word.length != 10 && highestScoreWord.length === 10) { | ||
| highestScoreWord = highestScoreWord; | ||
| } else if (word.length === highestScoreWord) { | ||
| highestScoreWord = highestScoreWord; |
There was a problem hiding this comment.
Since the highestScoreWord is already the highestScoreWord, these else if statements can be removed.
No description provided.