Skip to content

Sapphire - Hannah Chandley Wohllaib #136

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

hannahredfive
Copy link

Thank you!!

Copy link

@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!

X: 8,
Y: 4,
Z: 10,
}

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 on lines +59 to +61
const getRandomInt = (max) => {
return Math.floor(Math.random() * max);
}

Choose a reason for hiding this comment

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

Great helper function!

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);
}

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!

const inputUpper = input.toUpperCase();

for (const letter of inputUpper) {
if (lettersInHandMap.has(letter) === true) {

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

@@ -145,7 +147,7 @@ describe("Adagrams", () => {
const words = ["XXX", "XXXX", "X", "XX"];
const correct = { word: "XXXX", score: scoreWord("XXXX") };

throw "Complete test by adding an assertion";
expect(highestScoreFrom(words)).toEqual(correct);

Choose a reason for hiding this comment

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

Nice!

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];
}
};

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