-
Notifications
You must be signed in to change notification settings - Fork 103
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
Madi Jackson #87
base: main
Are you sure you want to change the base?
Madi Jackson #87
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 @@ | ||
{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,166 @@ | ||
const LETTER_POOL = { | ||
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 LETTER_SCORE = { | ||
'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 drawLetters = () => { | ||
// Implement this method for wave 1 | ||
let fullHand = []; | ||
let myHand = []; | ||
for (let [key, value] of Object.entries(LETTER_POOL)){ | ||
fullHand.push(...Array(value).fill(key)); | ||
} | ||
Comment on lines
+60
to
+62
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. Great combination of iteration and the spread operator to create the letter pool to draw from. |
||
while (myHand.length < 10){ | ||
let randomChoice = Math.floor(Math.random() * fullHand.length); | ||
myHand.push(fullHand[randomChoice]); | ||
fullHand.splice(randomChoice, 1); | ||
} | ||
return myHand; | ||
}; | ||
|
||
export const usesAvailableLetters = (input, lettersInHand) => { | ||
// Implement this method for wave 2 | ||
let testWord = []; | ||
let wordDict = {}; | ||
Comment on lines
+72
to
+73
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. We should prefer using const anywhere we don't need to reassign values - Lists & dictionaries are mutable, we can declare them as const and still add new values, we just then can't re-assign the variable to a new array or dictionary. |
||
input.toUpperCase(); | ||
|
||
for (let letter of input){ | ||
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. Love the thought to use a frequency map here! |
||
if (letter in wordDict){ | ||
++wordDict[letter]; | ||
} else { | ||
wordDict[letter] === 1; | ||
} | ||
} | ||
|
||
for (let [key, value] of Object.entries(lettersInHand)){ | ||
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. While javascript allows this syntax, looking at the tests, for (let letter of lettersInHand) {
... |
||
if (input.includes(value)){ | ||
testWord.push(value); | ||
} | ||
} | ||
let finalWord = testWord.join(''); | ||
if (finalWord === input){ | ||
Comment on lines
+89
to
+90
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. There's a bug caused by these lines that I'd like you to try troubleshooting. What happens if it("returns true when word contains letters in the drawn letters out of order", () => {
const drawn = ["G", "D", "O", "X", "X", "X", "X", "X", "X", "X"];
const word = "DOG";
const isValid = usesAvailableLetters(word, drawn);
expect(isValid).toBe(true);
});
it("returns true when drawn letters contains duplicates of letters in word", () => {
const drawn = ["D", "O", "G", "G", "X", "X", "X", "X", "X", "X"];
const word = "DOG";
const isValid = usesAvailableLetters(word, drawn);
expect(isValid).toBe(true);
}); |
||
return true; | ||
} else { | ||
return false; | ||
} | ||
Comment on lines
+92
to
+94
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. We could remove the else block here and unindent |
||
}; | ||
|
||
export const scoreWord = (word) => { | ||
// Implement this method for wave 3 | ||
let scoreBoard = 0; | ||
let bonus = 8; | ||
let myWord = word.toUpperCase(); | ||
for (let letter of myWord){ | ||
if (letter in LETTER_SCORE){ | ||
scoreBoard += LETTER_SCORE[letter]; | ||
} | ||
} | ||
if (myWord.length >= 7){ | ||
scoreBoard += bonus; | ||
} | ||
Comment on lines
+106
to
+108
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 could be a great place for a ternary operator: // Ternary operator structure:
// var = (conditional) ? (value if true) : (value if false)
scoreBoard = (myWord.length >= 7) ? (score + bonus) : score |
||
return scoreBoard; | ||
}; | ||
|
||
export const highestScoreFrom = (words) => { | ||
// Implement this method for wave 4 | ||
let wordDict = {}; | ||
let winnersList= {}; | ||
let lengthList = {}; | ||
Comment on lines
+114
to
+115
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. We could remove these dictionaries since it looks like they're only referenced in the commented out code. |
||
|
||
for (let letter 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. In this case we're iterating over a list of words rather than letters, I suggest updating the variable name |
||
let score = scoreWord(letter); | ||
wordDict[letter] = score; | ||
// if (letter.length === 10){ | ||
// return (letter, score); | ||
// } else{ | ||
// continue; | ||
// } | ||
} | ||
let counter = 0 | ||
let contestants = '' | ||
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 |
||
for (let [key,value] of Object.entries(wordDict)){ | ||
if (value > counter){ | ||
counter = value; | ||
contestants = key; | ||
}else if (value === counter){ | ||
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. Small style best practice: we should include a space after a closing brace before any following key words. |
||
if (contestants.length === 10){ | ||
continue; | ||
}else if (key.length < contestants.length){ | ||
contestants = key; | ||
}else if (key.length === 10){ | ||
contestants = key; | ||
} | ||
} | ||
} | ||
return {word: contestants, score: counter}; | ||
// const maxValue = wordDict.reduce(); | ||
|
||
// for (let key of wordDict){ | ||
// if (wordDict[key] === (key, maxValue)){ | ||
// let draft = (key, maxValue); | ||
// winnersList.push(draft); | ||
// } | ||
// } | ||
|
||
// for (let [key, value] in Object.entries(winnersList)){ | ||
// let len = key.length; | ||
// lengthList.push(len) | ||
// } | ||
|
||
// let tieBreaker = Math.min(lengthList); | ||
|
||
// if (winnersList.length > 0){ | ||
// for (let winner of winnersList){ | ||
// if (winner[0].length === tieBreaker){ | ||
// return winner; | ||
// } | ||
// } | ||
// } | ||
}; |
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.
Tiny best practices note: The spacing between data structures/functions and indentation isn't consistent across the file, just something to keep in mind to take a look for before opening PRs.