-
Notifications
You must be signed in to change notification settings - Fork 44
Sphinx - Brianna R. #32
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
mikellewade
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.
Nice work! Please let me know if there are any questions about the comments made.
| for (const [key, value] of Object.entries(letterPool)) { | ||
| for (let i = 0; i < value; i++) { | ||
| letterFrequency.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.
Nice work finding the javascript version of .items!
| do{ | ||
| const position = Math.floor(Math.random() * (letterFrequency.length-1)); | ||
| const randomLetter = letterFrequency[position]; | ||
| hand.push(randomLetter); | ||
| letterFrequency.splice(position, 1); | ||
| i++; | ||
| } while (i <= 10); |
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.
Is there a particular reason as to why you implemented a do...while loop rather than a while loop? The only difference is that the do...while loop is guaranteed to run at least once, but this isn't necessarily being leveraged here. (If you were just testing things out feel free to ignore this comment.)
| i++; | ||
| } while (i <= 10); | ||
|
|
||
| return hand; |
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.
Something extra to think about is how you could implement this same functionality with the ... syntax that is provided and if you think it provides any advantages against what you have.
| const letterList = [] | ||
| const letterBankCopy = lettersInHand.slice() | ||
|
|
||
| for (let 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, you used the appropriate for loop!
| for (let letter of word) { | ||
| if (letterBankCopy.includes(letter)) { | ||
| letterList.push(letter); | ||
| letterBankCopy.splice(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.
These are inputs are going to be the same size (10) 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?
| const upperCaseWord = word.toUpperCase(); | ||
| let score = 0; | ||
|
|
||
| for (let letter of upperCaseWord) { | ||
| score = score + scoreChart[letter]; | ||
| }; | ||
|
|
||
| if (word.length > 6) { | ||
| score = score + 8; | ||
| }; | ||
| console.log(score); | ||
| return score; |
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! Don't forget to remove your console.logs!
| } else if (score < bestScore) { | ||
| null; |
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.
Is this line serving some purpose I don't see? Right now it seems like it isn't actually contributing to your logic.
| }; | ||
| let result = {score: bestScore, word : bestWord}; | ||
| return result; | ||
| }; |
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.