-
Notifications
You must be signed in to change notification settings - Fork 20
Ocelots - Kelly T #13
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
kelsey-steven-ada
left a comment
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.
Looks good! I’ve added some suggestions, let me know if there's anything I can clarify ^_^
| for (let [key,value] of Object.entries(letterCounts)) { | ||
| for (let i = 0; i < value; ++i) { | ||
| letterPool.push(key); | ||
| } | ||
| } |
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.
Really nice solution for ensuring we get the desired distribution of letters.
I would consider moving the creation of the letterPool variable to directly above this loop to keep it right next to where it gets used.
| const shuffle = function (letterPool) { | ||
| letterPool.sort(() => Math.random() - 0.5); | ||
| } |
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.
Really neat implementation 😄
| } else { | ||
| wordCount[letter] = 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.
Great use of frequency maps.
| if (!(key in letterBankCount)) { | ||
| return false; | ||
| } | ||
| if (wordCount[key] > letterBankCount[key]) { | ||
| 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.
If the line doesn't get too long, I suggest combining these into one if-statement so we can have one false return.
| word = word.toUpperCase(); | ||
|
|
||
| let points = 0; |
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.
I would consider moving these lines to below scoreChart, or at least the initialization of points so they are right next to where they get used. This can make reading easier since there's no need to scroll if you have to remind yourself of what a value was initialized as.
| } | ||
|
|
||
| // Calculate score for each word | ||
| for (const letter of word) { |
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 use of a for...of loop.
| for (const letter of word) { | ||
| points += scoreChart[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.
This could have an unexpected result if the string word has characters that aren't in scoreChart. If we have an input like "ABC DEF" then points will hold NaN (Not a Number) after the loop. If we wanted to skip non-alphabetic characters or characters that aren't in scoreChart, how could we do that?
| let winner; | ||
|
|
||
| // Determine highestScore and winner | ||
| for (const wordEntry in scores) { |
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 implementation to tie break in a single loop!
No description provided.