-
Notifications
You must be signed in to change notification settings - Fork 44
C22 Sphinx - Christelle Nkera #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| for (let letter in LETTER_POOL) { | ||
| let originalLetterCount = LETTER_POOL[letter]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment found above could apply here as well. Again, these are constant sized inputs but consider if they weren't.
| } | ||
| } | ||
|
|
||
| return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice function!
|
|
||
| export const scoreWord = (word) => { | ||
| // Implement this method for wave 3 | ||
| const pointsDict = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have dictionaries in Javascript? 👀
| totalPoints += BONUS_POINTS; | ||
| } | ||
|
|
||
| return totalPoints; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, very legible function!
| } | ||
| } | ||
|
|
||
| return { word: bestWord, score: bestScore }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on making this logic easy to follow!
No description provided.