Skip to content
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

Zoisite - Muniba K. #137

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

Zoisite - Muniba K. #137

wants to merge 5 commits into from

Conversation

bashmu33
Copy link

@bashmu33 bashmu33 commented Jun 5, 2023

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.

Great work on your first javascript project 🎉 I've added some questions & comments below, please take a look when you have a moment and reach out here or on Slack if I can clarify anything =]

Comment on lines +45 to +49
let countLetters = 0;
while (countLetters < frequency) {
arrLetterPool.push(letter);
countLetters++;
}

Choose a reason for hiding this comment

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

If we didn't want to manage the count ourself, a for loop would work great here:

for (let [letter, frequency] of Object.entries(LETTER_POOL)) {
    for (let i = 0; i < frequency; i++) {
        arrLetterPool.push(letter);
    }
}


while (drawnLetters.length < 10) {
let randomLetter = Math.floor(Math.random() * arrLetterPool.length);
let removedLetter = arrLetterPool.splice(randomLetter, 1)[0];

Choose a reason for hiding this comment

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

Great use for splice! Another way to get the single value from what splice returns is with array unpacking syntax:

    const [removedLetter] = availablePool.splice(randomIndex, 1);

export const usesAvailableLetters = (input, lettersInHand) => {
// Implement this method for wave 2
};
let lettersInHandCopy = Array.from(lettersInHand);

Choose a reason for hiding this comment

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

Another common syntax for copying arrays is the spread operator ...:

const lettersInHandCopy = [...lettersInHand];

const currentLetter = input[i];
//Line below is needed because the letterIndex is what is used to loop through the lettersInHandCopy array
//If the currentLetter is not found, indexOf() returns -1.
const letterIndex = lettersInHandCopy.indexOf(currentLetter)

Choose a reason for hiding this comment

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

indexOf needs to scan through a list to find the element to return the index, what is the time complexity of this function overall? What strategies could we use to try and reduce the complexity?

Comment on lines +86 to +88
if (word.length >= 7) {
score += 8;
}

Choose a reason for hiding this comment

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

This could be a great place for a ternary operator:

// Ternary operator structure: 
// var = (conditional) ? (value if true) : (value if false)
score = (word.length >= 7) ? (score + 8) : score


for (let letter of wordUpper) {
for (let [points, letters] of Object.entries(SCORE_CHART_DICT)) {
if (letters.includes(letter)) {

Choose a reason for hiding this comment

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

If you want to use the current data formatting of SCORE_CHART_DICT, I would strongly consider changing SCORE_CHART_DICT to use sets for the values to store the letters for each score key so that we can check for membership in O(1) time. When they are arrays includes will scan through each element in the list to check for membership.

Comment on lines +117 to +122
if (shortestWord.length === 10) {
shortestWord = shortestWord;
} else if (word.length === 10) {
shortestWord = word;
} else if (word.length < shortestWord.length) {
shortestWord = word;

Choose a reason for hiding this comment

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

Since the result is no change for the first conditional, we could refactor to remove the assignment of shortestWord to itself. There are many ways to approach it, one option is to use variables to represent the conditionals we need to consider:

const isBestTen = shortestWord.length === 10
const isWordTen = word.length === 10
const isWordShorter = word.length < shortestWord.length
if ((isWordTen && !isBestTen) || (isWordShorter && !isBestTen)) {
    shortestWord = word;
}

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