Conversation
yangashley
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
What scenario is this else block supposed to handle? Do we need it?
| return false; | ||
| } | ||
| } | ||
| return true; |
There was a problem hiding this comment.
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.