Skip to content

C22 Sphinx - Christelle Nkera#35

Open
scnkera wants to merge 3 commits intoAda-C22:mainfrom
scnkera:main
Open

C22 Sphinx - Christelle Nkera#35
scnkera wants to merge 3 commits intoAda-C22:mainfrom
scnkera:main

Conversation

@scnkera
Copy link
Copy Markdown

@scnkera scnkera commented Nov 27, 2024

No description provided.

Comment thread src/adagrams.js
Comment on lines +12 to +13
for (let letter in LETTER_POOL) {
let originalLetterCount = LETTER_POOL[letter];
Copy link
Copy Markdown

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)){
    // ...

Comment thread src/adagrams.js
const letter = availableLetters[randomIndex];

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

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 thread src/adagrams.js
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;
}
Copy link
Copy Markdown

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.

Comment thread src/adagrams.js
}
}

return true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice function!

Comment thread src/adagrams.js

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

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? 👀

Comment thread src/adagrams.js
totalPoints += BONUS_POINTS;
}

return totalPoints;
Copy link
Copy Markdown

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!

Comment thread src/adagrams.js
}
}

return { word: bestWord, score: bestScore };
Copy link
Copy Markdown

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