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

Snow Leopards - Aretta B. #127

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

Snow Leopards - Aretta B. #127

wants to merge 4 commits into from

Conversation

arettab
Copy link

@arettab arettab commented Dec 8, 2022

No description provided.

Copy link

@marciaga marciaga left a comment

Choose a reason for hiding this comment

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

Great job! I'd suggest going over the requirements just to be sure you're not missing anything such as accounting for the distribution of letters in building a hand. Generally good use of const vs let where appropriate.


const letters = Object.keys(letterPool);
let hand = [];
while (hand.length < 10) {

Choose a reason for hiding this comment

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

Nice job creating the hand! I'm not seeing where you account for the distribution of letters though. Seems like all letters have an equal chance of being selected.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry to seem like I'm being sensitive over this because I see I you still gave me green on this assignment and I appreciate it, but I really thought I got it right. I even ran to test 10 times in a row to make sure it worked. To my understanding, while const object keys are immutable their values aren't, so every time the loop ran can choose a letter from the list of keys it would go back and subtract from the value of that letter in the letter pool. The letter only got added to the hand if its matching value was above 0. Maybe I didn't do line 37 correctly. Please let me know.

Choose a reason for hiding this comment

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

No problem! The function is getting letters from letterPool just fine, but it isn't accounting for the distribution of letters, so it should be the case that because the letter pool should contain 9 Is and 1 J, that it's 9 times more likely to draw an I. Think of it in an array form, simplified:

['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B',...]

If we generated a random index based on the length of this array, it would be much more likely to be an A. But yours works a bit differently. You generate a number between 1 and 26 and that is used as an index to key off of the letterPool object, so all letters have a 1 in 26 chance of being selected, whereas in the array above, if we created an array that had all the letters according to their distribution, which would produce an array of size 98, we'd end up with a 9/98 chance of drawing an A. As for the decrementing, you're right that you need to decrement the value of each letter in the letter pool to make sure there are available tiles to draw and put into the hand, but there's a mismatch between letters and letterPool which is why the distribution of letters isn't accurate.

};

export const usesAvailableLetters = (input, lettersInHand) => {
// Implement this method for wave 2
const testWord = input.toUpperCase();

Choose a reason for hiding this comment

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

Good job with this function!

};

export const scoreWord = (word) => {
// Implement this method for wave 3
const scoreChart= {

Choose a reason for hiding this comment

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

This score chart object could be moved into the main scope so it wouldn't be created each time the function scoreWord is called. Also, note the object keys in JavaScript don't need quotes.



const scoredWordsArray = Array.from(scoredWords.entries());
function checkWord(word) {

Choose a reason for hiding this comment

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

Since checkWord is only used in the filter callback, it would be tidier to write the filter function with an inline anonymous arrow function, i.e.

  const highScoreWords = scoredWordsArray.filter(word => word[1] === highscore);

const highScoreWords = scoredWordsArray.filter(checkWord)


let smallestWordLength = Infinity

Choose a reason for hiding this comment

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

There's some accidental indentation starting here on line 128 through 140.

};

export const highestScoreFrom = (words) => {
// Implement this method for wave 4
const scoredWords = new Map();

Choose a reason for hiding this comment

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

The highestScoreFrom function works great! I'd suggest simplifying the data structure transformations wherever possible, e.g. setting up a Map object isn't doing anything that a plain object can't.

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

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.

Nice 👍🏽

scoredWords.set(word,scoreWord(word));
});

let scores = scoredWords.values();

Choose a reason for hiding this comment

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

I don't see where these variables are reassigned, so they should be const

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