Conversation
| for (let letter in LETTER_POOL) { | ||
| let originalLetterCount = LETTER_POOL[letter]; |
There was a problem hiding this comment.
We could use Object.entries as well to get the functionality and cut out the key accessing you have here like so:
for (const [letter, freq] of Object.entries(LETTER_POOL)){
// ...| const letter = availableLetters[randomIndex]; | ||
|
|
||
| currentHand.push(letter); | ||
| availableLetters.splice(randomIndex, 1); |
There was a problem hiding this comment.
These are letter counts will the same size but what if they weren't? What if the input size varied? What would be the time complexity of your code? What CS fundamentals data structure did we learn about that is handy for keeping track of the number of occurrences?
| for (const inputLetter of word) { | ||
| const letterFreqInLetterBank = lettersInHand.filter((letter) => letter === inputLetter).length; | ||
| const letterFreqInWord = word.split('').filter((letter) => letter === inputLetter).length; | ||
|
|
||
| if (letterFreqInWord > letterFreqInLetterBank) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
The comment found above could apply here as well. Again, these are constant sized inputs but consider if they weren't.
| } | ||
| } | ||
|
|
||
| return true; |
|
|
||
| export const scoreWord = (word) => { | ||
| // Implement this method for wave 3 | ||
| const pointsDict = { |
There was a problem hiding this comment.
Do we have dictionaries in Javascript? 👀
| totalPoints += BONUS_POINTS; | ||
| } | ||
|
|
||
| return totalPoints; |
| } | ||
| } | ||
|
|
||
| return { word: bestWord, score: bestScore }; |
There was a problem hiding this comment.
Great work on making this logic easy to follow!
No description provided.