-
Notifications
You must be signed in to change notification settings - Fork 169
Jessica Hebert -C18 Snow Leopards #129
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"name": "vscode-jest-tests.v2", | ||
"request": "launch", | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"disableOptimisticBPs": true, | ||
"cwd": "${workspaceFolder}", | ||
"runtimeExecutable": "yarn", | ||
"args": [ | ||
"test", | ||
"--runInBand", | ||
"--watchAll=false", | ||
"--testNamePattern", | ||
"${jest.testNamePattern}", | ||
"--runTestsByPath", | ||
"${jest.testFile}" | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"jest.jestCommandLine": "yarn test" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,126 @@ | ||
export const drawLetters = () => { | ||
// Implement this method for wave 1 | ||
}; | ||
const letterPool={ | ||
A: 9, | ||
B: 2, | ||
C: 2, | ||
D: 4, | ||
E: 12, | ||
F: 2, | ||
G: 3, | ||
H: 2, | ||
I: 9, | ||
J: 1, | ||
K: 1, | ||
L: 4, | ||
M: 2, | ||
N: 6, | ||
O: 8, | ||
P: 2, | ||
Q: 1, | ||
R: 6, | ||
S: 4, | ||
T: 6, | ||
U: 4, | ||
V: 2, | ||
W: 2, | ||
X: 1, | ||
Y: 2, | ||
Z: 1 | ||
}; | ||
const availableLetters = []; | ||
|
||
for (const [letter,frequency] of Object.entries(letterPool)){ | ||
for (let i = 0;i< frequency;i++){ | ||
availableLetters.push(letter)} | ||
} | ||
const hand=[] | ||
for (let i = 0; i < 10; i++) { | ||
const thisLetter = availableLetters[Math.floor(Math.random() * availableLetters.length)] | ||
hand.push(thisLetter) | ||
let letterIndex = availableLetters.indexOf(thisLetter) | ||
availableLetters.splice(letterIndex, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you remove the letter by using splice with |
||
} | ||
|
||
return hand; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be indented once |
||
}; | ||
|
||
export const usesAvailableLetters = (input, lettersInHand) => { | ||
// Implement this method for wave 2 | ||
const upperCase = input.toUpperCase(); | ||
|
||
for (let letter of upperCase) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you ever reassign letter in the for loop? It doesn't look like it so we should use const instead of let |
||
if (lettersInHand.includes(letter)) { | ||
let index = lettersInHand.indexOf(letter) | ||
lettersInHand.splice(index, 1) | ||
} else { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
const letterScores = { | ||
A: 1, | ||
B: 3, | ||
C: 3, | ||
D: 2, | ||
E: 1, | ||
F: 4, | ||
G: 2, | ||
H: 4, | ||
I: 1, | ||
J: 8, | ||
K: 5, | ||
L: 1, | ||
M: 3, | ||
N: 1, | ||
O: 1, | ||
P: 3, | ||
Q: 10, | ||
R: 1, | ||
S: 1, | ||
T: 1, | ||
U: 1, | ||
V: 4, | ||
W: 4, | ||
X: 8, | ||
Y: 4, | ||
Z: 10 | ||
}; | ||
|
||
export const scoreWord = (word) => { | ||
// Implement this method for wave 3 | ||
|
||
let score = 0; | ||
let bonus = 8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I like that you put the extra bonus points in a variable. Since it is a constant value that we hardcode to 8 and don't change, we can rename it BONUS. Also, since you don't reassign |
||
word = word.toUpperCase(); | ||
|
||
for (let i = 0; i < word.length; i++) { | ||
score += letterScores[word[i]]; | ||
} | ||
Comment on lines
+95
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use a for-of loop here to iterate over ever letter in word.
|
||
|
||
if (word.length >= 7 && word.length < 11) { | ||
score += bonus; | ||
} | ||
return score; | ||
|
||
}; | ||
|
||
export const highestScoreFrom = (words) => { | ||
// Implement this method for wave 4 | ||
let highestWord = ''; | ||
let highestScore = 0; | ||
|
||
for (let word of words){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're not reassigning word we should use const |
||
let score = scoreWord(word); | ||
if (score> highestScore){ | ||
highestScore = score; | ||
highestWord = word; | ||
}else if (score == highestScore){ | ||
if(highestWord.length==10){ | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to break out of the loop or continue on with the loop? |
||
}else if (word.length == 10 || word.length< highestWord.length){ | ||
highestWord = word; | ||
highestScore = score; | ||
} | ||
} | ||
} | ||
return {'score':highestScore, 'word':highestWord} | ||
}; |
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 JS doesn't care about white spaces, we should add spaces after each semi-colon on line 33.