Skip to content

Conversation

anika-sw
Copy link

@anika-sw anika-sw commented Jan 4, 2023

No description provided.

@anika-sw anika-sw changed the title Obligatory title Snow Leopards | Anika SW Jan 4, 2023
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 job on this project! I left some comments about alternate approaches to consider as well. Let me know if you have questions about the comments.

const STARTING_NUMBER = 1
const MAX_DRAW = 10

const WEIGHTED_LETTERS = {

Choose a reason for hiding this comment

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

Two notes here:

A way to keep your projects organized is to put large constant variables like this in a separate file and then import the data from that file into the places it needs to be used. Here's an example of how to do it.

The other thing is, what if you had a dictionary where the key was a letter and the value was the frequency of a letter {A: 9, B: 2, C: 2}. How would you iterate over this object to create a list of 98 letters to represent the frequency distribution?

98: 'Z'
};

const LETTER_VALUES = {

Choose a reason for hiding this comment

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

Nice job using const. We can use const for mutable objects and still add/remove from the object or array, we just can't reassign what LETTER_VALUES references

Comment on lines +156 to +167
for (let i = 0; keysArray.length < MAX_DRAW; i++) {
const key = pickRandomNumber();
if (!keysArray.includes(key)) {
keysArray.push(key);
}
}

for (const key of keysArray) {
let tileLetter = WEIGHTED_LETTERS[key];
lettersInHand.push(tileLetter);
}

Choose a reason for hiding this comment

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

Could these two for-loops be combined into one loop? How would your logic need to change so you could get a random key and push the associated letter into lettersInHand?

Comment on lines +189 to +191
} else {
return false;
}

Choose a reason for hiding this comment

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

What scenario is this else block supposed to handle? Do we need it?

return false;
}
}
return true;

Choose a reason for hiding this comment

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

Another approach for checking if the input uses available letters is to loop through input with a for loop and check that the letter at each index is included in lettersInHand

 for (let i = 0; i < input.length; i++) {
    let letter = input[i];
    if (lettersInHand.includes(letter)) {
      let letterIndex = lettersInHand.indexOf(letter);
      lettersInHand.splice(letterIndex, 1);
    } else {
      return false;
    }
  }
  return true;
};

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