-
Notifications
You must be signed in to change notification settings - Fork 50
Leaves - Bri #38
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: master
Are you sure you want to change the base?
Leaves - Bri #38
Changes from all commits
49fc234
d39ff7b
a7a38d5
8465965
2ce35d1
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 |
---|---|---|
@@ -1,8 +1,97 @@ | ||
const poolOfLetters = ( | ||
"A".repeat(9) + | ||
"B".repeat(2) + | ||
"C".repeat(2) + | ||
"D".repeat(4) + | ||
"E".repeat(12) + | ||
"F".repeat(2) + | ||
"G".repeat(3) + | ||
"H".repeat(2) + | ||
"I".repeat(9) + | ||
"J".repeat(1) + | ||
"K".repeat(1) + | ||
"L".repeat(4) + | ||
"M".repeat(2) + | ||
"N".repeat(6) + | ||
"O".repeat(8) + | ||
"P".repeat(2) + | ||
"Q".repeat(1) + | ||
"R".repeat(6) + | ||
"S".repeat(4) + | ||
"T".repeat(6) + | ||
"U".repeat(4) + | ||
"V".repeat(2) + | ||
"W".repeat(2) + | ||
"X".repeat(1) + | ||
"Y".repeat(2) + | ||
"Z".repeat(1) | ||
).split(''); | ||
|
||
const valueHash = {"A": 1, "E": 1, "I": 1, "O": 1, "U": 1, "L": 1, "N": 1, "R": 1, "S": 1, "T": 1, "D": 2, "G": 2, "B": 3, "C": 3, "M": 3, "P": 3, "F": 4, "H": 4, "V": 4, "W": 4, "Y": 4, "K": 5, "J": 8, "X": 8, "Q": 10, "Z": 10}; | ||
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. style note: each letter should be on it's own line. |
||
|
||
const Adagrams = { | ||
// thank you stackoverflow: https://stackoverflow.com/questions/3718282/javascript-shuffling-objects-inside-an-object-randomize | ||
shuffle(letterbank) { | ||
for (let i = 0; i < letterbank.length - 1; i++) { | ||
let j = i + Math.floor(Math.random() * (letterbank.length - i)); | ||
|
||
let temp = letterbank[j]; | ||
letterbank[j] = letterbank[i]; | ||
letterbank[i] = temp; | ||
} | ||
}, | ||
|
||
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. Here, you shuffle the entire array pool of letters... and then, you take the first ten. Consider how you could refactor this so that you randomly pick ten letters, instead of shuffling the entire array. |
||
drawLetters() { | ||
// Implement this method for wave 1 | ||
let poolOfLettersCopy = [...poolOfLetters] | ||
this.shuffle(poolOfLettersCopy) | ||
return poolOfLettersCopy.slice(0,10); | ||
}, | ||
|
||
usesAvailableLetters(input, lettersInHand) { | ||
|
||
// Create frequency hash of lettersInHand | ||
let handHash = new Object(); | ||
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. consider this syntax |
||
for (let l of lettersInHand) { | ||
if (handHash.hasOwnProperty(l)) { | ||
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.
|
||
handHash[l] += 1; | ||
} | ||
else { | ||
handHash[l] = 1; | ||
} | ||
} | ||
|
||
// Check if characters from input are in handHash | ||
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 seems overly nested. Consider how your might refactor using compound conditionals. |
||
for (let l of input) { | ||
if (l in handHash) { | ||
if (handHash[l] == 0) { | ||
return false | ||
} | ||
else { | ||
handHash[l] -= 1 | ||
} | ||
} | ||
else { | ||
return false | ||
} | ||
} | ||
return true | ||
}, | ||
|
||
// Wave 3 | ||
scoreWord(word){ | ||
let score = 0; | ||
let bonus = 8; | ||
|
||
for (let l of word) { | ||
score += valueHash[l.toUpperCase()]; | ||
} | ||
if (word.length == 7 || word.length == 8 || word.length == 9 || word.length == 10){ | ||
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. consider |
||
score += bonus; | ||
} | ||
return score; | ||
} | ||
}; | ||
|
||
// Do not remove this line or your tests will break! | ||
export default Adagrams; | ||
|
||
|
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.
It would be best to include each of these objects
poolOfLetters
andvalueHash
inside the Adagrams module (I know this is different then what I said last week :)