-
Notifications
You must be signed in to change notification settings - Fork 50
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
Branches - Amal #34
base: master
Are you sure you want to change the base?
Branches - Amal #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,104 @@ | ||
const Adagrams = { | ||
|
||
drawLetters() { | ||
// Implement this method for wave 1 | ||
// // // Implement this method for wave 1 | ||
let letterPool = [ | ||
Array(9).fill('A'),Array(2).fill('B'),Array(2).fill('C'), | ||
Array(4).fill('D'),Array(12).fill('E'),Array(2).fill('F'), | ||
Array(3).fill('G'),Array(2).fill('H'),Array(9).fill('I'), | ||
Array(1).fill('J'),Array(1).fill('K'),Array(4).fill('L'), | ||
Array(2).fill('M'),Array(6).fill('N'),Array(8).fill('O'), | ||
Array(2).fill('P'),Array(1).fill('Q'),Array(6).fill('R'), | ||
Array(4).fill('S'),Array(6).fill('T'),Array(4).fill('U'), | ||
Array(2).fill('V'),Array(2).fill('W'),Array(1).fill('X'), | ||
Array(2).fill('Y'),Array(1).fill('Z'), | ||
|
||
|
||
].flat(2); | ||
|
||
let hand = []; | ||
|
||
for (let i = 0; i < 10; i += 1) { | ||
const randomIndex = Math.floor(Math.random() * 99); | ||
hand.push(letterPool[randomIndex]); | ||
} | ||
|
||
return hand; | ||
|
||
}, | ||
}; | ||
|
||
usesAvailableLetters(word, hand) { | ||
let handObj = {}; | ||
let result = true; | ||
|
||
hand.forEach(function(letter){ | ||
if(handObj[letter] ){ | ||
handObj[letter] += 1; | ||
}else{ | ||
handObj[letter] = 1; | ||
} | ||
|
||
}) | ||
|
||
word.split('').forEach(function(letter){ | ||
if (handObj[letter]){ | ||
handObj[letter] -= 1; | ||
if (handObj[letter] == 0) { | ||
delete handObj[letter]; | ||
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. Instead of using this |
||
} | ||
}else { | ||
result = false; | ||
} | ||
}) | ||
return result; | ||
|
||
}, | ||
|
||
scoreWord(word) { | ||
let score = 0; | ||
let letterScore = { | ||
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.
|
||
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, | ||
|
||
} | ||
word.toUpperCase().split('').forEach(function(letter){ | ||
score += letterScore[letter] | ||
}) | ||
if (word.length >= 7){ | ||
score += 8 | ||
} | ||
|
||
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.
Where does this
99
come from? If it represents something (like the length ofletterPool
), maybe give it a variable name. If it doesn't, then how can we make this number meaningful?