-
Notifications
You must be signed in to change notification settings - Fork 169
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
Amethyst - Hannah Watkins #142
base: main
Are you sure you want to change the base?
Conversation
…count for empty str input
const letterPool = [ | ||
...Array(9).fill('A'), | ||
...Array(2).fill('B'), | ||
...Array(2).fill('C'), | ||
...Array(4).fill('D'), | ||
...Array(12).fill('E'), | ||
...Array(2).fill('F'), | ||
...Array(3).fill('G'), | ||
...Array(2).fill('H'), | ||
...Array(9).fill('I'), | ||
'J', | ||
'K', | ||
...Array(4).fill('L'), | ||
...Array(2).fill('M'), |
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.
Hi Hannah! Great job completing JS Adagrams! Congrats on finishing your first JavaScript project 🎉 Excellent choice with this data structure. There's a lot of repeated code here, how can we make this program more DRY?
while (hand.length < 10) { | ||
const randomIndex = Math.floor(Math.random() * letterPool.length); | ||
const letter = letterPool[randomIndex]; | ||
|
||
if (hand.filter((l) => l === letter).length < letterPool.filter((l) => l === letter).length) { | ||
hand.push(letter); | ||
} |
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 use of filter()
⭐️
const handCopy = [...lettersInHand]; | ||
|
||
for (const letter of input) { | ||
const index = handCopy.indexOf(letter); | ||
|
||
if (index === -1) { | ||
return false; | ||
} | ||
|
||
handCopy.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.
Nice job translating this logic 👍🏾
while (hand.length < 10) { | ||
const randomIndex = Math.floor(Math.random() * letterPool.length); | ||
const letter = letterPool[randomIndex]; | ||
|
||
if (hand.filter((l) => l === letter).length < letterPool.filter((l) => l === letter).length) { | ||
hand.push(letter); | ||
} | ||
} | ||
|
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 translating this logic 👍🏾
for (const letter of input) { | ||
const index = handCopy.indexOf(letter); | ||
|
||
if (index === -1) { | ||
return false; | ||
} | ||
|
||
handCopy.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.
Great work!
const letterScores = { | ||
A: 1, E: 1, I: 1, O: 1, | ||
U: 1, L: 1, N: 1, R: 1, | ||
S: 1, T: 1, D: 2, G: 2, | ||
B: 3, C: 3, M: 3, P: 3, | ||
F: 4, H: 4, V: 4, W: 4, | ||
Y: 4, K: 5, J: 8, X: 8, | ||
Q: 10, Z: 10, | ||
}; | ||
|
||
let score = 0; | ||
|
||
for (const letter of word.toUpperCase()) { | ||
score += letterScores[letter]; | ||
} | ||
|
||
if (word.length >= 7 && word.length <= 10) { | ||
score += 8; | ||
} |
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 work getting comfortable with JavaScript's syntax. It looks like you're getting use to looping over data and adding conditional logic ✅
highestScoringWords = [{ word, score }]; | ||
} else if (score === highestScore) { | ||
highestScoringWords.push({ word, score }); |
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 work using this object to implement this solution ✅
No description provided.