Skip to content

Conversation

@scnkera
Copy link

@scnkera scnkera commented Nov 27, 2024

No description provided.

Comment on lines +12 to +13
for (let letter in LETTER_POOL) {
let originalLetterCount = LETTER_POOL[letter];

Choose a reason for hiding this comment

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

We could use Object.entries as well to get the functionality and cut out the key accessing you have here like so:

for (const [letter, freq] of Object.entries(LETTER_POOL)){
    // ...

const letter = availableLetters[randomIndex];

currentHand.push(letter);
availableLetters.splice(randomIndex, 1);

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?

Comment on lines +35 to +41
for (const inputLetter of word) {
const letterFreqInLetterBank = lettersInHand.filter((letter) => letter === inputLetter).length;
const letterFreqInWord = word.split('').filter((letter) => letter === inputLetter).length;

if (letterFreqInWord > letterFreqInLetterBank) {
return false;
}

Choose a reason for hiding this comment

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

The comment found above could apply here as well. Again, these are constant sized inputs but consider if they weren't.

}
}

return true;

Choose a reason for hiding this comment

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

Nice function!


export const scoreWord = (word) => {
// Implement this method for wave 3
const pointsDict = {

Choose a reason for hiding this comment

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

Do we have dictionaries in Javascript? 👀

totalPoints += BONUS_POINTS;
}

return totalPoints;

Choose a reason for hiding this comment

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

Nice work, very legible function!

}
}

return { word: bestWord, score: bestScore };

Choose a reason for hiding this comment

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

Great work on making this logic easy to follow!

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