Skip to content

Conversation

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

@@ -1,15 +1,173 @@
const SIZE_OF_DRAW = 10;

Choose a reason for hiding this comment

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

I like having a value for this that we could change in just one place if we wanted to update it.

@@ -1,15 +1,173 @@
const SIZE_OF_DRAW = 10;
const LETTER_VALUES = {

Choose a reason for hiding this comment

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

Since LETTER_VALUES is only accessed by the scoreWord function, it would be reasonable to place the object inside the function 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 other functions couldn't access it to accidentally alter the contents.

Z: 10,
};

const genPoolLetters = (poolRulesObj) => {

Choose a reason for hiding this comment

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

Nice helper to generate the letter distribution array to index into.

Comment on lines +75 to +83
const draw = [];
const poolLetters = genPoolLetters(poolRules);

while (draw.length < SIZE_OF_DRAW) {
let randNum = getRandomNumber(poolLetters.length);
draw.push(poolLetters[randNum]);
poolLetters.splice(randNum, 1);
}
return draw;

Choose a reason for hiding this comment

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

I love how nicely laid out this is and how easy it is to read with the helper functions.

Comment on lines +107 to +112
if (letterBank[letter] == undefined) {
return false;
}
if (letterBank[letter] == 0) {
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.

if (!input || lettersInHand === []) {
return false;
}
const letterBank = createLettersInHandDict(lettersInHand);

Choose a reason for hiding this comment

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

Nice use of a frequency map =]

if (letterBank[letter] == undefined) {
return false;
}
if (letterBank[letter] == 0) {

Choose a reason for hiding this comment

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

In javascript we should use === to make a strict comparison against value and type. This article gets into more of the distinctions between == and === which might be helpful: https://www.scaler.com/topics/javascript/difference-between-double-equals-and-triple-equals-in-javascript/

Comment on lines +124 to +130
for (let i = 0; i < word.length; ++i) {
let letter = word[i];
if (LETTER_VALUES[letter] != undefined) {
// If its undefined means letter is a special character
points += LETTER_VALUES[letter];
}
}

Choose a reason for hiding this comment

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

We could simplify this loop a little with a for...of loop:

for (const letter of word) {
    if (LETTER_VALUES[letter] != undefined) {
        // If its undefined means letter is a special character
        points += LETTER_VALUES[letter];
    }
}

}
let points = 0;
word = word.toUpperCase();
for (let i = 0; i < 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.

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