Skip to content

Conversation

@smchavan
Copy link

No description provided.

Copy link

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

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

"X": 1,
"Y": 2,
"Z": 1
};

Choose a reason for hiding this comment

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

Small style nitpick: I would consider outdenting this closing bracket so it line up with the beginning of line 2.

Comment on lines +32 to +33
let lettersInHand = [];
while (count < 10){

Choose a reason for hiding this comment

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

We could remove the variable count and directly check the length of lettersInHand in the condition.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you !

const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let lettersInHand = [];
while (count < 10){
let letterChosen = characters.charAt(Math.floor(Math.random() * 26));

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?

Copy link
Author

Choose a reason for hiding this comment

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

Maybe I will use dictionary of letters to pick random characters. Will do some more research on this.

Comment on lines +59 to +67
for (let i=0; i< input.length; i++){
if(dictOfLettersInHand[input[i]] == null){
return false;
} else if (dictOfLettersInHand[input[i]]===0)
{
return false;
}
dictOfLettersInHand[input[i]] -= 1;
}

Choose a reason for hiding this comment

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

Nice approach, I like the use of a frequency map.

To make this a little easier to read and reduce repetition, you could pull dictOfLettersInHand[input[i]] into a variable before the if-statements:

for (let i = 0; i < input.length; i++) {
    letterValue = dictOfLettersInHand[input[i]]
    if (letterValue == null || letterValue === 0) {
        return false;
    }

    dictOfLettersInHand[input[i]] -= 1;
}

Comment on lines +59 to +60
for (let i=0; i< input.length; i++){
if(dictOfLettersInHand[input[i]] == null){

Choose a reason for hiding this comment

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

Small style issue: we should indent the contents of for-loops so it's clear what code is inside the block.

Comment on lines +102 to +103
if (word.length === 0)
{

Choose a reason for hiding this comment

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

Specific teams might have their own conventions, but typically we place the opening brace on the same line as the if-statement.

Comment on lines +100 to +101
let pointsForWord = 0;
let upperCaseWord = word.toUpperCase();

Choose a reason for hiding this comment

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

I suggest placing these variable declarations under the if statement below so they are only created if they will be used.

Comment on lines +107 to +111
for (let i =0; i< upperCaseWord.length; i++){
if (upperCaseWord.charAt(i) in lettersDictionary){
pointsForWord += lettersDictionary[upperCaseWord.charAt(i)];
}
}

Choose a reason for hiding this comment

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

We could simplify this loop a little with a for...of loop:

for (const letter of upperCaseWord) {
    if (lettersDictionary[letter] != undefined) {
        // If its undefined means letter is a special character
        pointsForWord += lettersDictionary[letter];
    }
}

return 0;
}
//Code to add scores of the letters in the word
for (let i =0; i< upperCaseWord.length; i++){

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.

@smchavan
Copy link
Author

Thank you for your detailed comments. I will remember those and make the changes accordingly.

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