Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .vscode/launch.json
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}"
]
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"jest.jestCommandLine": "yarn test"
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.8.0",
"babel-plugin-module-resolver": "^3.2.0",
"eslint": "^8.29.0",
"eslint-plugin-jest": "^27.1.6",
"jest": "^24.8.0",
"regenerator-runtime": "^0.12.1"
},
Expand Down
119 changes: 115 additions & 4 deletions src/adagrams.js
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++){

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.

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)

Choose a reason for hiding this comment

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

Could you remove the letter by using splice with thisLetter instead?

}

return hand;

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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;

Choose a reason for hiding this comment

The 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 bonus, we should use const

word = word.toUpperCase();

for (let i = 0; i < word.length; i++) {
score += letterScores[word[i]];
}
Comment on lines +95 to +97

Choose a reason for hiding this comment

The 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.

for (letter of word) {
   score += letterScores[letter]
}


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){

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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}
};
Loading