C22 Sphinx Somy C#28
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.
| const letterValue = new Map([ | ||
| [['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], 1], | ||
| [['D', 'G'], 2], | ||
| [['B', 'C', 'M', 'P'], 3], | ||
| [['F', 'H', 'V', 'W', 'Y'], 4], | ||
| [['K'], 5], | ||
| [['J', 'X'], 8], | ||
| [['Q', 'Z'], 10] | ||
| ]); |
There was a problem hiding this comment.
Nice to see you using different constructors and getting familiar with them!
| // Implement this method for wave 1 | ||
|
|
||
| let lettersList = []; | ||
| for (const [letter, count] of Object.entries(letterPool)) { |
There was a problem hiding this comment.
Nice work finding the javascript version of .items!
| } | ||
|
|
||
| let hand = []; | ||
| let temporaryLettersList = [...lettersList]; |
There was a problem hiding this comment.
Nice, love to see the spread syntax being used!
|
|
||
| for (let i = 0; i < 10; i++) { | ||
| const randomIndex = Math.floor(Math.random() * temporaryLettersList.length); | ||
| const randomLetter = temporaryLettersList.splice(randomIndex, 1)[0]; |
There was a problem hiding this comment.
These are letter counts will the same size 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 index = lettersInHand.indexOf(letter); | ||
| lettersInHand.splice(index, 1); |
There was a problem hiding this comment.
You are currently mutating a mutable object, if the caller of the function is not expecting this it could lead to some difficult to debug errors.
| for (let i = 0; i < word.length; i++) { | ||
| let letter = word[i].toUpperCase(); | ||
|
|
||
| for (let [letters, score] of letterValue) { |
There was a problem hiding this comment.
Since you used a Map object you get access to this nice concise/readable syntax!
| if (word.length === 0){ | ||
| return 0; | ||
| } | ||
|
|
||
| let totalScore = 0 | ||
| for (let i = 0; i < word.length; i++) { | ||
| let letter = word[i].toUpperCase(); | ||
|
|
||
| for (let [letters, score] of letterValue) { | ||
| if (letters.includes(letter)) { | ||
| totalScore += score; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if (word.length > 6){ | ||
| totalScore += 8 | ||
| } | ||
| return totalScore |
| for (let word of words) { | ||
| let currentScore = scoreWord(word); | ||
|
|
||
| if (currentScore > winner.score) { | ||
| winner = { word, score: currentScore }; | ||
| } | ||
|
|
||
| else if (currentScore === winner.score) { | ||
| if (word.length === 10 && winner.word.length !== 10) { | ||
| winner = { word, score: currentScore }; | ||
| } | ||
|
|
||
| else if ( | ||
| word.length !== 10 && | ||
| winner.word.length !== 10 && | ||
| word.length < winner.word.length | ||
| ) { | ||
| winner = { word, score: currentScore }; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Your nested statements look good, easy to follow!
| expectScores({ | ||
| "": 0 | ||
| }); |
No description provided.