Sapphire - Hannah Chandley Wohllaib#136
Open
hannahredfive wants to merge 8 commits intoAda-C18:mainfrom
Open
Conversation
…, implimented getRandomInt and drawLetters
… Passed all tests for wave 4.
…ere are 2 tests failing. second time tests are run they all pass. this implies an issue with statefulness
goeunpark
reviewed
Aug 16, 2023
goeunpark
left a comment
There was a problem hiding this comment.
Wonderful job, Hannah! 🎉
This submission nails all the learning goals. I'm excited to see your JS in the world wide web!
| X: 8, | ||
| Y: 4, | ||
| Z: 10, | ||
| } |
There was a problem hiding this comment.
Love to see the two constants LETTER_VALUE and LETTER_POOL up top! 🧡
Comment on lines
+59
to
+61
| const getRandomInt = (max) => { | ||
| return Math.floor(Math.random() * max); | ||
| } |
Comment on lines
+68
to
+79
| const randomLetter = alphabet[getRandomInt(26)]; | ||
| const quantity = LETTER_POOL[randomLetter]; | ||
| let counter = 0; | ||
|
|
||
| for (let i = 0; i < drawnLetters.length; i++) { | ||
| if (drawnLetters[i] === randomLetter) { | ||
| counter += 1; | ||
| } | ||
| } | ||
| if (counter < quantity) { | ||
| drawnLetters.push(randomLetter); | ||
| } |
There was a problem hiding this comment.
This doesn't quite mimic the action of pulling out a random letter form a bag of properly weighted letters (here, there's an equal chance of pulling out a E as a Z due to L28, despite E being much more likely to be drawn) but it's a good start!
| const inputUpper = input.toUpperCase(); | ||
|
|
||
| for (const letter of inputUpper) { | ||
| if (lettersInHandMap.has(letter) === true) { |
There was a problem hiding this comment.
Refactor to:
if (lettersInHandMap.has(letter)) {
| const correct = { word: "XXXX", score: scoreWord("XXXX") }; | ||
|
|
||
| throw "Complete test by adding an assertion"; | ||
| expect(highestScoreFrom(words)).toEqual(correct); |
Comment on lines
+114
to
138
| const tieBreaker = (potentialWinningWords) => { | ||
| const tenLetterWords = []; | ||
| const shortestWords = []; | ||
| let shortestWordLength = 11 | ||
|
|
||
| for (const word of potentialWinningWords) { | ||
| if (word.length === 10) { | ||
| tenLetterWords.push(word) | ||
| } else if (word.length < shortestWordLength) { | ||
| shortestWordLength = word.length; | ||
| } | ||
| } | ||
|
|
||
| for (const word of potentialWinningWords) { | ||
| if (word.length === shortestWordLength) { | ||
| shortestWords.push(word); | ||
| } | ||
| } | ||
|
|
||
| if (tenLetterWords.length > 0) { | ||
| return tenLetterWords[0]; | ||
| } else { | ||
| return shortestWords[0]; | ||
| } | ||
| }; |
There was a problem hiding this comment.
Great tiebreaker logic in a neat helper function!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you!!