Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Sharks - Morgan B. #93

wants to merge 9 commits into from

Conversation

Morfiend
Copy link

@Morfiend Morfiend commented Jun 7, 2022

No description provided.

Copy link

@yangashley yangashley left a 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!

Comment on lines +41 to +53
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;
}
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Comment on lines +60 to +78
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +88 to +90
if (word.length > 6) {
score += 8;
}

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];

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants