-
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
Sharks - Morgan B. #93
base: main
Are you sure you want to change the base?
Conversation
passed wave2 tests
wrote empty string test, passes wave3 tests
tests adjusted, code passes wave4 and all tests
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 on js-adagrams! Your project shows that you have a good handle on javascript so far!
I had a comment about an additional check you could add to scoreWord() so that you can handle scoring words that include characters that may not be in the alphabet and a suggested refactor for drawLetters()
🟢 for the project!
while (returnedLetters.length < 10) { | ||
let currentLetter = | ||
letterList[Math.floor(Math.random() * letterList.length)]; | ||
returnedLetters.push(currentLetter); | ||
for (let i = 0; i < letterList.length; i++) { | ||
if (letterList[i] === currentLetter) { | ||
letterList.splice(i, 1); | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
} |
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.
while (returnedLetters.length < 10) { | |
let currentLetter = | |
letterList[Math.floor(Math.random() * letterList.length)]; | |
returnedLetters.push(currentLetter); | |
for (let i = 0; i < letterList.length; i++) { | |
if (letterList[i] === currentLetter) { | |
letterList.splice(i, 1); | |
{ | |
break; | |
} | |
} | |
} | |
} | |
while (returnedLetters.length < 10) { | |
const letterIndex = Math.floor(Math.random() * letterList.length); | |
const currentLetter = letterList[letterIndex]; | |
returnedLetters.push(currentLetter); | |
letterList.splice(letterIndex, 1); | |
} | |
return returnedLetters; |
let letterDict = {}; | ||
|
||
for (const letter of lettersInHand) { | ||
if (letterDict.hasOwnProperty(letter.toUpperCase())) { | ||
letterDict[letter] += 1; | ||
} else { | ||
letterDict[letter] = 1; | ||
} | ||
} | ||
|
||
for (const letter of input) { | ||
if (letterDict[letter] > 0) { | ||
letterDict[letter] -= 1; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
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.
👍
if (word.length > 6) { | ||
score += 8; | ||
} |
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.
You might also see this written with a ternary operator (on line 83):
let score = word.length >= 7 ? 8 : 0;
let score = 0; | ||
|
||
for (const letter of word) { | ||
score += letterFreqAndScore[letter.toUpperCase()][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.
How would you handle input that has characters that are not in letterFreqAndScore
, for example what if word was "cat!" ?
When your for loop gets to "!" then letterFreqAndScore['!'] will return undefined
. When we add undefined
to a number like total
then the result will be NaN, which introduces a bug.
You could have a conditional check before adding score to total, by checking that the letter is a key in letterScore.
No description provided.