-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: main
Are you sure you want to change the base?
Sharks: Gricelda #113
Conversation
There was a problem hiding this 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 = { |
There was a problem hiding this comment.
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.
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); | ||
} | ||
}); |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
if (inputLength > 6 && inputLength < 11) { | ||
score += 8; | ||
} |
There was a problem hiding this comment.
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;
expectScores({ | ||
'': 0, | ||
}); |
There was a problem hiding this comment.
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++) { |
There was a problem hiding this comment.
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
No description provided.