-
Notifications
You must be signed in to change notification settings - Fork 44
Sphinx - Vlada Rapaport #44
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
base: main
Are you sure you want to change the base?
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 job on js-adagrams!
@@ -1,15 +1,163 @@ | |||
export const drawLetters = () => { | |||
// Implement this method for wave 1 | |||
const 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.
While we use the const
keyword to ensure the values cannot be reassigned, we should also use capital letters to convey to other devs the value is fixed.
const letterPool = { | |
const LETTER_POOL = { |
} | ||
|
||
const randomlyHand = []; | ||
const lettersCountDict = { |
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 lettersCountDict = { | |
const LETTERS_COUNT = { |
Recall that Javascript doesn't have dictionaries. It has objects.
Z: 0, | ||
}; | ||
|
||
while (randomlyHand.length < 10) { |
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.
Prefer to reference the integer 10 with a variable. This makes your code more readable/self documenting because it clues other devs in to the meaning of 10
.
while (randomlyHand.length < 10) { | |
const HAND_LENGTH = 10; | |
while (randomlyHand.length < HAND_LENGTH) { |
}; | ||
|
||
while (randomlyHand.length < 10) { | ||
const i = Math.floor(Math.random() * letters.length); |
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.
Prefer more descriptive name for this variable, maybe like randomIndex
let wordLower = input.toLowerCase(); | ||
|
||
for (let letter of lettersInHand) { | ||
lettersInHandCopy.push(letter.toLowerCase()); | ||
} | ||
|
||
for (let letter of wordLower) { |
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.
2 notes:
-
If your looping variable
letter
is not updated in the loop, then we should useconst
instead. -
To make your code more concise, call
toLowerCase()
when you need it:
let wordLower = input.toLowerCase(); | |
for (let letter of lettersInHand) { | |
lettersInHandCopy.push(letter.toLowerCase()); | |
} | |
for (let letter of wordLower) { | |
for (const letter of lettersInHand.toLowerCase()) { | |
lettersInHandCopy.push(letter); | |
} | |
for (const letter of input.toLowerCase()) { |
if (!lettersInHandCopy.includes(letter)) { | ||
return false; | ||
} else { | ||
lettersInHandCopy.splice(lettersInHandCopy.indexOf(letter), 1); |
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.
splice
like python's remove
has linear time complexity with respect to the length of the list. This won't be a problem for the size of data we're working with, but consider using a strategy of virtually "dividing" the list into a used and unused side. Swapping a value to the used side would be constant time!
}; | ||
|
||
export const scoreWord = (word) => { | ||
// Implement this method for wave 3 | ||
const scoreDict = { |
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 scoreDict = { | |
const SCORE_DICT = { |
const bonusLengthMin = 7; | ||
const bonusLengthMax = 10; | ||
const bonusPoints = 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.
Use all caps for naming thees constant variables
}; | ||
|
||
export const highestScoreFrom = (words) => { | ||
// Implement this method for wave 4 | ||
const tieBreakingLength = 10; |
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 tieBreakingLength = 10; | |
const TIE_BREAKING_LENGTH = 10; |
let maxWord = words[0]; | ||
let maxScore = scoreWord(maxWord); | ||
|
||
for (let i = 1; i < words.length; 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.
Prefer for
/of
loop instead because we don't need i
to access the letter we want to score.
No description provided.