-
Notifications
You must be signed in to change notification settings - Fork 112
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
Otters - Jodi Denney #98
base: main
Are you sure you want to change the base?
Conversation
Otters - Jodi Denney |
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 job, Jodi! 🎉
Your tests all pass and this implementation is production-worthy code! You have a clear understanding of const
and let
and constant variables in JS, your for
loops shine, and your semicolons are used with consistency! This project is a Green. 🟢
Keep up the great work! 💖
@@ -145,7 +147,7 @@ describe("Adagrams", () => { | |||
const words = ["XXX", "XXXX", "X", "XX"]; | |||
const correct = { word: "XXXX", score: scoreWord("XXXX") }; | |||
|
|||
throw "Complete test by adding an assertion"; | |||
expect(highestScoreFrom(words)).toEqual(correct); |
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.
👍🏻
@@ -1,15 +1,123 @@ | |||
// import { LETTER_POOL } from "../test/adagrams.test"; | |||
const LETTER_POOL = { |
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 the JS constant variable here at the top of the file! ✨
// Build a letterBank array where each letters appearance is accurately weighted | ||
for (const [key, count] of Object.entries(LETTER_POOL)) { | ||
const start = letterBank.length; | ||
letterBank.length += count; | ||
letterBank.fill(key, start, letterBank.length); | ||
} |
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.
Rad! This totally works and I learned about Object.entries()
syntax from this bit of code so thank you! Another way we could go about this:
for (const letter in LETTER_POOL) {
for (let i = 0; i < LETTER_POOL[letter]; i++) {
letterBank.push(letter)
}
}
for (let i = 0; i < 10; i++) { | ||
let temp = Math.floor(Math.random() * letterBank.length); | ||
hand.push(letterBank[temp]); | ||
letterBank.splice(temp, 1); | ||
} | ||
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.
Mmmm, love the JS syntax for randomly picking 10 numbers (not really but this is probably the best way we can do this)!
}; | ||
|
||
export const usesAvailableLetters = (input, lettersInHand) => { | ||
// Implement this method for wave 2 | ||
input = input.toUpperCase(); |
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 way to standardize the input! 💯
}; | ||
|
||
export const usesAvailableLetters = (input, lettersInHand) => { | ||
// Implement this method for wave 2 | ||
input = input.toUpperCase(); | ||
let handCopy = [...lettersInHand]; |
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.
Delicious destructuring on this line! 👨🏻🍳
for (let i = 0; i < word.length; i++) { | ||
score += LETTER_SCORE[word[i]]; | ||
} | ||
if (word.length > 6) { |
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.
Almost! The instructions for Wave 3 says If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points
so we should add a second conditional here to get the right range!
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 see your point but if you tried to pass on any word with more than ten letters you wouldnt have made it past UsesAvailableLetters and your dirty cheater word would have ben declared invalid prior to scoring. So setting the upper limit at 10 here is redundant and I saved at least six whole key strokes! Thank you for all the kind words. Made me smile.
if (word.length > 6) { | ||
score += 8; | ||
} | ||
return score; | ||
}; | ||
|
||
export const highestScoreFrom = (words) => { |
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 logic for highestScoreFrom
! 🚀
No description provided.