-
Notifications
You must be signed in to change notification settings - Fork 169
Snow Leopards | Anika SW #134
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 = { |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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
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); | ||
} | ||
|
There was a problem hiding this comment.
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
?
} else { | ||
return false; | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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;
};
No description provided.