-
Notifications
You must be signed in to change notification settings - Fork 44
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
C22 Sphinx Somy C #28
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work finding the javascript version of .items
!
} | ||
|
||
let hand = []; | ||
let temporaryLettersList = [...lettersList]; |
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, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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.
Great function all around!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your nested statements look good, easy to follow!
expectScores({ | ||
"": 0 | ||
}); |
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.
⭐️
No description provided.