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

Zoisite - Whitney Shake #67

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

Zoisite - Whitney Shake #67

wants to merge 17 commits into from

Conversation

WhitShake
Copy link

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!

I left a comment about the distribution of letters when you draw a random letter. Let me know if you have questions about it.

There are several of places that const would have been a better fit over let. When in doubt, use const and then swap to let when the JS interpreter complains. Additionally, I noticed you relied on the for-i loop throughout the project, but most of your loops could have used a for-of loop. When we don't need the index to access a value, we should use the for-of loop.

I also called out a couple of places where the conditional logic should be simplified which would increase code readability. What you have does work and passes the tests, but with so many nested conditionals that rely on continue, it was a little difficult to follow along without using the debugger to see what each line of code was executing and why. I suggest revisiting these areas and refactoring for practice.

Overall, good work on converting your python adagrams to javscript!

@@ -1,15 +1,331 @@
const LETTER_POOL = {

Choose a reason for hiding this comment

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

Nice job naming constant variables with all caps

let lettersInHand = [];

while (lettersInHand.length < 10) {
let newNum = Math.floor(Math.random() * (26 + 1));

Choose a reason for hiding this comment

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

instead of hardcoding 26, prefer to use a variable that describes what the value is or you could use letterArray.length too.

Also, newNum is not re-assigned in the while loop so you should use const

Comment on lines +19 to +21
let letterArray = Object.keys(LETTER_POOL);
let tempLetters = {};
let lettersInHand = [];

Choose a reason for hiding this comment

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

These values are not re-assigned and should be declared with const. I tend to define everything with const and then switch them to let when the JS interpreter complains.

Comment on lines +26 to +28
if (currentLetter === undefined) {
continue;
}

Choose a reason for hiding this comment

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

Instead of writing this condition and then just using continue, maybe you could add another condition to line 29 and then remove lines 26-28 completely.

So line 29 could be like:
if (currentLetter !== undefined and (!currentLetter in tempLetters)) {}

Comment on lines +39 to +40
else {
continue;

Choose a reason for hiding this comment

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

Do we need this?

};

export const highestScoreFrom = (words) => {
// Implement this method for wave 4
let scoreArray = getScoreArray(words);

Choose a reason for hiding this comment

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

Most of the variables in this method should be declared with const since they are not reassigned.

let tieBreaker = getTieBreaker(potentialWinners, lengthArray);
return {"word": tieBreaker, "score": highScore};
}
};

Choose a reason for hiding this comment

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

👍 I like the helper functions you wrote to use in highestScoreFrom. The tie breaking logic is pretty complex so breaking each part of the logic into helper functions keeps this function concise and readable.

Comment on lines +123 to +125
expectScores({
'': 0,
});

Choose a reason for hiding this comment

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

👍

@@ -145,7 +147,8 @@ describe("Adagrams", () => {
const words = ["XXX", "XXXX", "X", "XX"];
const correct = { word: "XXXX", score: scoreWord("XXXX") };

throw "Complete test by adding an assertion";
// throw "Complete test by adding an assertion";
expect(highestScoreFrom(words)).toEqual(correct);

Choose a reason for hiding this comment

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

👍

return highScore;
};

const getPotentialWinners = (words, scoreArray, highScore) => {

Choose a reason for hiding this comment

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

This method relies on the words array and the scoreArray to be the same length since they both use i to access the values. However relying on this fact and that the words and scores are in the same order can be tricky. If you have two lists holding words and their scores, could you use an object to associate words with their scores instead?

You can still iterate over the object to find the potentialWinners

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