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

Sharks: Gricelda #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Sharks: Gricelda #113

wants to merge 1 commit into from

Conversation

GitHub4Gigi
Copy link

No description provided.

Copy link

@yangashley yangashley 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 on js-adagrams! Your project shows that you have a good handle on javascript so far!

I had comments about using const instead of let and how you can use the ternary operator in JS.

🟢 for the project!

@@ -1,15 +1,158 @@
const LETTER_POOL = {

Choose a reason for hiding this comment

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

Nice job following JS convention for naming variables that are constants.

Comment on lines +60 to +68
const letters = Object.keys(LETTER_POOL);

// letterPool list and then append(push) for each letter in the letter_Pool into the list(array)
let letterPool = [];
letters.forEach(function (letter) {
for (let i = 0; i < LETTER_POOL[letter]; i++) {
letterPool.push(letter);
}
});

Choose a reason for hiding this comment

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

👍

// then we need to push the newLetterpool into hand
// return hand array
let hand = [];
let newLetterpool = [...letterPool];

Choose a reason for hiding this comment

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

Nice use of the spread operator

// if empty must return 0
const inputArray = input.split("");
const inputLength = input.length;
let letterInHand = [...lettersInHand];

Choose a reason for hiding this comment

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

I think this line is making a copy of lettersInHand so that you can use letterInHand to splice from it without mutating the array that's passed into the method.

Consider renaming letterInHand to something like copyOfLetters since the two variable names above are so similar looking - letterInHand just has one less 's' so it compromises readability a little bit

let score = 0;
for (let i = 0; i < inputLength; i++) {
let letter = inputArray[i];
if (letters.includes(letter)) {

Choose a reason for hiding this comment

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

Nice check here!

If a letter isn't in letters then if you when line 118 executes, calling letterScore[letter] would return undefined on the right side. Adding undefined to an integer would return NaN and would introduce a bug.

Comment on lines +121 to +123
if (inputLength > 6 && inputLength < 11) {
score += 8;
}

Choose a reason for hiding this comment

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

You could also refactor line 114 when you first declare score to precalculate the bonus for a long word.

let score = word.length >= 7 ? 8 : 0;

Comment on lines +123 to +125
expectScores({
'': 0,
});

Choose a reason for hiding this comment

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

👍

const inputArray = input.split("");
const inputLength = input.length;
let letterInHand = [...lettersInHand];
for (let i = 0; i < inputLength; i++) {

Choose a reason for hiding this comment

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

Since i isn't being reassigned in the for loop, we can use const instead. Whenever you write a loop, you can check to see if the variable, like i or whatever variable you name the element, is being updated in the for loop. If it's not, then we should use const

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