Skip to content

Ocelots - Nadxelle Hernandez - #4

Open
nadxelleHernandez wants to merge 4 commits into
ada-ac2:mainfrom
nadxelleHernandez:main
Open

Ocelots - Nadxelle Hernandez#4
nadxelleHernandez wants to merge 4 commits into
ada-ac2:mainfrom
nadxelleHernandez:main

Conversation

@nadxelleHernandez

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

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 thread src/adagrams.js
@@ -1,15 +1,173 @@
const SIZE_OF_DRAW = 10;

Copy link
Copy Markdown

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.

Comment thread src/adagrams.js
@@ -1,15 +1,173 @@
const SIZE_OF_DRAW = 10;
const LETTER_VALUES = {

Copy link
Copy Markdown

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.

Comment thread src/adagrams.js
Z: 10,
};

const genPoolLetters = (poolRulesObj) => {

Copy link
Copy Markdown

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 thread src/adagrams.js
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;

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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 thread src/adagrams.js
if (!input || lettersInHand === []) {
return false;
}
const letterBank = createLettersInHandDict(lettersInHand);

Copy link
Copy Markdown

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

Comment thread src/adagrams.js
if (letterBank[letter] == undefined) {
return false;
}
if (letterBank[letter] == 0) {

Copy link
Copy Markdown

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 thread src/adagrams.js
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];
}
}

Copy link
Copy Markdown

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

Comment thread src/adagrams.js
}
let points = 0;
word = word.toUpperCase();
for (let i = 0; i < word.length; ++i) {

Copy link
Copy Markdown

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