Skip to content

Sapphire - Hannah Chandley Wohllaib#136

Open
hannahredfive wants to merge 8 commits intoAda-C18:mainfrom
hannahredfive:main
Open

Sapphire - Hannah Chandley Wohllaib#136
hannahredfive wants to merge 8 commits intoAda-C18:mainfrom
hannahredfive:main

Conversation

@hannahredfive
Copy link
Copy Markdown

Thank you!!

Copy link
Copy Markdown

@goeunpark goeunpark left a comment

Choose a reason for hiding this comment

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

Wonderful job, Hannah! 🎉

This submission nails all the learning goals. I'm excited to see your JS in the world wide web!

Comment thread src/adagrams.js
X: 8,
Y: 4,
Z: 10,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Love to see the two constants LETTER_VALUE and LETTER_POOL up top! 🧡

Comment thread src/adagrams.js
Comment on lines +59 to +61
const getRandomInt = (max) => {
return Math.floor(Math.random() * max);
}
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 helper function!

Comment thread src/adagrams.js
Comment on lines +68 to +79
const randomLetter = alphabet[getRandomInt(26)];
const quantity = LETTER_POOL[randomLetter];
let counter = 0;

for (let i = 0; i < drawnLetters.length; i++) {
if (drawnLetters[i] === randomLetter) {
counter += 1;
}
}
if (counter < quantity) {
drawnLetters.push(randomLetter);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't quite mimic the action of pulling out a random letter form a bag of properly weighted letters (here, there's an equal chance of pulling out a E as a Z due to L28, despite E being much more likely to be drawn) but it's a good start!

Comment thread src/adagrams.js
const inputUpper = input.toUpperCase();

for (const letter of inputUpper) {
if (lettersInHandMap.has(letter) === 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.

Refactor to:

if (lettersInHandMap.has(letter)) {

Comment thread test/adagrams.test.js
const correct = { word: "XXXX", score: scoreWord("XXXX") };

throw "Complete test by adding an assertion";
expect(highestScoreFrom(words)).toEqual(correct);
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!

Comment thread src/adagrams.js
Comment on lines +114 to 138
const tieBreaker = (potentialWinningWords) => {
const tenLetterWords = [];
const shortestWords = [];
let shortestWordLength = 11

for (const word of potentialWinningWords) {
if (word.length === 10) {
tenLetterWords.push(word)
} else if (word.length < shortestWordLength) {
shortestWordLength = word.length;
}
}

for (const word of potentialWinningWords) {
if (word.length === shortestWordLength) {
shortestWords.push(word);
}
}

if (tenLetterWords.length > 0) {
return tenLetterWords[0];
} else {
return shortestWords[0];
}
};
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 tiebreaker logic in a neat helper function!

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