Sphinx - Brianna R.#32
Conversation
mikellewade
left a comment
There was a problem hiding this comment.
Nice work! Please let me know if there are any questions about the comments made.
| for (const [key, value] of Object.entries(letterPool)) { | ||
| for (let i = 0; i < value; i++) { | ||
| letterFrequency.push(key) | ||
| }; | ||
| }; |
There was a problem hiding this comment.
Nice work finding the javascript version of .items!
| do{ | ||
| const position = Math.floor(Math.random() * (letterFrequency.length-1)); | ||
| const randomLetter = letterFrequency[position]; | ||
| hand.push(randomLetter); | ||
| letterFrequency.splice(position, 1); | ||
| i++; | ||
| } while (i <= 10); |
There was a problem hiding this comment.
Is there a particular reason as to why you implemented a do...while loop rather than a while loop? The only difference is that the do...while loop is guaranteed to run at least once, but this isn't necessarily being leveraged here. (If you were just testing things out feel free to ignore this comment.)
| i++; | ||
| } while (i <= 10); | ||
|
|
||
| return hand; |
There was a problem hiding this comment.
Something extra to think about is how you could implement this same functionality with the ... syntax that is provided and if you think it provides any advantages against what you have.
| const letterList = [] | ||
| const letterBankCopy = lettersInHand.slice() | ||
|
|
||
| for (let letter of word) { |
There was a problem hiding this comment.
Nice, you used the appropriate for loop!
| for (let letter of word) { | ||
| if (letterBankCopy.includes(letter)) { | ||
| letterList.push(letter); | ||
| letterBankCopy.splice(letter, 1) |
There was a problem hiding this comment.
These are inputs are going to be the same size (10) but what if they weren't? What if the input size varied? What would be the time complexity of your code? What CS fundamentals data structure did we learn about that is handy for keeping track of the number of occurrences?
| const upperCaseWord = word.toUpperCase(); | ||
| let score = 0; | ||
|
|
||
| for (let letter of upperCaseWord) { | ||
| score = score + scoreChart[letter]; | ||
| }; | ||
|
|
||
| if (word.length > 6) { | ||
| score = score + 8; | ||
| }; | ||
| console.log(score); | ||
| return score; |
There was a problem hiding this comment.
Nice work, very legible function! Don't forget to remove your console.logs!
| } else if (score < bestScore) { | ||
| null; |
There was a problem hiding this comment.
Is this line serving some purpose I don't see? Right now it seems like it isn't actually contributing to your logic.
| }; | ||
| let result = {score: bestScore, word : bestWord}; | ||
| return result; | ||
| }; No newline at end of file |
There was a problem hiding this comment.
Great work on making this logic easy to follow!
No description provided.