Skip to content

Conversation

@Hannah1Watkins
Copy link

No description provided.

Comment on lines +2 to +15
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'),

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?

Comment on lines +32 to +38
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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of filter() ⭐️

Comment on lines +46 to +55
const handCopy = [...lettersInHand];

for (const letter of input) {
const index = handCopy.indexOf(letter);

if (index === -1) {
return false;
}

handCopy.splice(index, 1);

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 👍🏾

Comment on lines +32 to +40
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);
}
}

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 👍🏾

Comment on lines +48 to +56
for (const letter of input) {
const index = handCopy.indexOf(letter);

if (index === -1) {
return false;
}

handCopy.splice(index, 1);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Comment on lines +67 to +85
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;
}

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 ✅

Comment on lines +101 to +103
highestScoringWords = [{ word, score }];
} else if (score === highestScore) {
highestScoringWords.push({ word, score });

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 ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants