Skip to content

Conversation

@marjanak
Copy link

No description provided.

Copy link
Collaborator

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

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

Nice work translating Adagrams to Javascript! Let me know if you have questions on any feedback =]

Comment on lines +33 to +34
let letters = Object.keys(letterPool);
let randomIndex = Math.floor(Math.random() * letters.length);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This implementation has the same distribution issue that I mentioned in the Python version where there is an equal chance to pick any letter since we are choosing from the keys. Even though the tests pass, this doesn't meet what the function description is asking for, so I would like you to revisit this if you have time.

Comment on lines +49 to +56
for (let letter of input) {
const index = lettersCopy.indexOf(letter);
if (index != -1) {
lettersCopy.splice(index, 1);
} else {
return false;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This implementation has an O(n^2) time complexity, how could we use a frequency map to bring the time complexity down to O(n)?

}
let totalScore = 0;
word = word.toUpperCase();
for (let i = 0; i < word.length; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could simplify the syntax inside the loop a little if we use a for-of loop to iterate directly over the letters in the parameter word:

for (const letter of word) {

Comment on lines +118 to +122
} else if (word.length === 10) {
highestWord = word;
} else if (word.length < highestWord.length) {
highestWord = word;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we combine these cases or do something else to reduce duplication of updating the highestWord variable?

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