Skip to content

AC2-Ocelots-Elaine(Si Ok) Sohn - #19

Open
sioksohn wants to merge 16 commits into
ada-ac2:mainfrom
sioksohn:main
Open

AC2-Ocelots-Elaine(Si Ok) Sohn #19
sioksohn wants to merge 16 commits into
ada-ac2:mainfrom
sioksohn:main

Conversation

@sioksohn

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good! I’ve added some suggestions, let me know if there's anything I can clarify ^_^

Comment thread src/adagrams.js
export const usesAvailableLetters = (input, lettersInHand) => {
// Implement this method for wave 2
};
LETTER_SCORE = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since these constants at the top of the file are only accessed by one function each, it would be reasonable to place the objects inside the functions rather than as a constant. There are tradeoffs, the structure would clutter the function some, but it keeps the data as close as possible to where it's being used, and would mean that other functions who shouldn't need it couldn't access it.

Comment thread src/adagrams.js
// Implement this method for wave 1
};
class Adagrams{
LETTER_POOL = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If these shouldn't be edited, I would consider creating them as a static, read-only properties: https://stackoverflow.com/a/35242218

Comment thread src/adagrams.js

drawLetters() {
while (this.lettersInHand.length < 10) {
let letter = String.fromCharCode(Math.floor(Math.random() * 26) + 65);

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 will give us an even chance of picking any single letter in the alphabet without going over the number of each tile we have. This is slightly different than what the README asks - we won't accurately represent the distribution of tiles because we pick a letter from 1-26, when the chances of picking some letters should be higher than others. How could we update the algorithm to account for this?

Comment thread src/adagrams.js
};

drawLetters() {
while (this.lettersInHand.length < 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.

Nice use of the hand length to control the while loop

Comment thread src/adagrams.js
Comment on lines +76 to +79
if (this.LETTER_POOL[letter] > 0) {
this.LETTER_POOL[letter] -= 1;
this.lettersInHand.push(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.

If we are directly editing this.LETTER_POOL, what will happen after we call drawLetters on the same instance many times in a row?

Comment thread src/adagrams.js
};

scoreWord(word) {
this.word = word.toUpperCase();

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 wouldn't typically hold onto the input of a function like this as an attribute on a class. If it isn't important to persist between function calls, then we should re-evaluate if it's something the class itself should hold.

Comment thread src/adagrams.js
Comment on lines +127 to +131
let point = 0;

for (let i=0; i < this.word.length; ++i){
point += this.LETTER_SCORE[this.word[i]];
}

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 simplify the syntax here a little with a for...of loop:

for (const letter of this.word) {
    point += this.LETTER_SCORE[letter];
}

Comment thread src/adagrams.js
}
let point = 0;

for (let i=0; i < this.word.length; ++i){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we won't be reassigning the loop variable in the body of a loop, I recommend using const over let to declare the variable.

Comment thread src/adagrams.js
Comment on lines +127 to +131
let point = 0;

for (let i=0; i < this.word.length; ++i){
point += this.LETTER_SCORE[this.word[i]];
}

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 could have an unexpected result if the string word has characters that aren't in LETTER_SCORE . If we have an input like "ABC DEF" then point will hold NaN (Not a Number) after the loop. If we wanted to skip non-alphabetic characters or characters that aren't in LETTER_SCORE , how could we do that?

Comment thread src/adagrams.js

highestScoreFrom(words) {

for (let word of words) {

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 solution to tie break in a single loop!

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