Skip to content

Conversation

@kellytate
Copy link

No description provided.

Copy link

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

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

Looks good! I’ve added some suggestions, let me know if there's anything I can clarify ^_^

Comment on lines +39 to +43
for (let [key,value] of Object.entries(letterCounts)) {
for (let i = 0; i < value; ++i) {
letterPool.push(key);
}
}

Choose a reason for hiding this comment

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

Really nice solution for ensuring we get the desired distribution of letters.

I would consider moving the creation of the letterPool variable to directly above this loop to keep it right next to where it gets used.

Comment on lines +46 to +48
const shuffle = function (letterPool) {
letterPool.sort(() => Math.random() - 0.5);
}

Choose a reason for hiding this comment

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

Really neat implementation 😄

} else {
wordCount[letter] = 1;
}
}

Choose a reason for hiding this comment

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

Great use of frequency maps.

Comment on lines +85 to +90
if (!(key in letterBankCount)) {
return false;
}
if (wordCount[key] > letterBankCount[key]) {
return false;
}

Choose a reason for hiding this comment

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

If the line doesn't get too long, I suggest combining these into one if-statement so we can have one false return.

Comment on lines +102 to +104
word = word.toUpperCase();

let points = 0;

Choose a reason for hiding this comment

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

I would consider moving these lines to below scoreChart, or at least the initialization of points so they are right next to where they get used. This can make reading easier since there's no need to scroll if you have to remind yourself of what a value was initialized as.

}

// Calculate score for each word
for (const letter of word) {

Choose a reason for hiding this comment

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

Nice use of a for...of loop.

Comment on lines +137 to +139
for (const letter of word) {
points += scoreChart[letter];
}

Choose a reason for hiding this comment

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

This could have an unexpected result if the string word has characters that aren't in scoreChart. If we have an input like "ABC DEF" then points will hold NaN (Not a Number) after the loop. If we wanted to skip non-alphabetic characters or characters that aren't in scoreChart, how could we do that?

let winner;

// Determine highestScore and winner
for (const wordEntry in scores) {

Choose a reason for hiding this comment

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

Nice implementation to tie break in a single loop!

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