Skip to content

Conversation

@sioksohn
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 ^_^

export const usesAvailableLetters = (input, lettersInHand) => {
// Implement this method for wave 2
};
LETTER_SCORE = {

Choose a reason for hiding this comment

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

Since these constants at the top of the file are only accessed by one function each, it would be reasonable to place the objects inside the functions rather than as a constant. There are tradeoffs, the structure would clutter the function some, but it keeps the data as close as possible to where it's being used, and would mean that other functions who shouldn't need it couldn't access it.

// Implement this method for wave 1
};
class Adagrams{
LETTER_POOL = {

Choose a reason for hiding this comment

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

If these shouldn't be edited, I would consider creating them as a static, read-only properties: https://stackoverflow.com/a/35242218


drawLetters() {
while (this.lettersInHand.length < 10) {
let letter = String.fromCharCode(Math.floor(Math.random() * 26) + 65);

Choose a reason for hiding this comment

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

This will give us an even chance of picking any single letter in the alphabet without going over the number of each tile we have. This is slightly different than what the README asks - we won't accurately represent the distribution of tiles because we pick a letter from 1-26, when the chances of picking some letters should be higher than others. How could we update the algorithm to account for this?

};

drawLetters() {
while (this.lettersInHand.length < 10) {

Choose a reason for hiding this comment

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

Nice use of the hand length to control the while loop

Comment on lines +76 to +79
if (this.LETTER_POOL[letter] > 0) {
this.LETTER_POOL[letter] -= 1;
this.lettersInHand.push(letter);
}

Choose a reason for hiding this comment

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

If we are directly editing this.LETTER_POOL, what will happen after we call drawLetters on the same instance many times in a row?

};

scoreWord(word) {
this.word = word.toUpperCase();

Choose a reason for hiding this comment

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

We wouldn't typically hold onto the input of a function like this as an attribute on a class. If it isn't important to persist between function calls, then we should re-evaluate if it's something the class itself should hold.

Comment on lines +127 to +131
let point = 0;

for (let i=0; i < this.word.length; ++i){
point += this.LETTER_SCORE[this.word[i]];
}

Choose a reason for hiding this comment

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

We could simplify the syntax here a little with a for...of loop:

for (const letter of this.word) {
    point += this.LETTER_SCORE[letter];
}

}
let point = 0;

for (let i=0; i < this.word.length; ++i){

Choose a reason for hiding this comment

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

If we won't be reassigning the loop variable in the body of a loop, I recommend using const over let to declare the variable.

Comment on lines +127 to +131
let point = 0;

for (let i=0; i < this.word.length; ++i){
point += this.LETTER_SCORE[this.word[i]];
}

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 LETTER_SCORE . If we have an input like "ABC DEF" then point will hold NaN (Not a Number) after the loop. If we wanted to skip non-alphabetic characters or characters that aren't in LETTER_SCORE , how could we do that?


highestScoreFrom(words) {

for (let word of words) {

Choose a reason for hiding this comment

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

Nice solution 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