-
Notifications
You must be signed in to change notification settings - Fork 49
Leaves - Emily Vomacka #51
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?
Changes from all commits
38a9c47
3b2c1c8
8985592
df4b0b9
c0adb37
bb65e8d
b7ffaf4
91525c0
a3ea4a4
84e1ac7
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,2 @@ | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ const presets = [ | |
| safari: "11.1", | ||
| }, | ||
| useBuiltIns: "usage", | ||
| corejs: 2, | ||
| }, | ||
| ], | ||
| ]; | ||
|
|
||
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,83 @@ | ||
| const Adagrams = { | ||
| drawLetters() { | ||
| // Implement this method for wave 1 | ||
| const letterPool = ('A'.repeat(10) + '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' + 'K' + 'L'.repeat(4) + 'M'.repeat(2) + 'N'.repeat(6) + 'O'.repeat(8) + 'P'.repeat(2) + 'Q' + 'R'.repeat(6) + 'S'.repeat(4) + 'T'.repeat(6) + 'U'.repeat(4) + 'V'.repeat(2) + 'W'.repeat(2) + 'X' + 'Y'.repeat(2) + 'Z').split(''); | ||
|
|
||
| const letterHandIndices = []; | ||
| do { | ||
|
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 use of the |
||
| let newIndex = Math.floor(Math.random() * letterPool.length); | ||
| if (!letterHandIndices.includes(newIndex)) { | ||
| letterHandIndices.push(newIndex) } | ||
| } | ||
| while (letterHandIndices.length < 10); | ||
|
|
||
| const letterHand = []; | ||
|
|
||
| letterHandIndices.forEach( function(index) { | ||
|
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 using an arrow function for the anonymous function in the forEach loop |
||
| letterHand.push(letterPool[index]) | ||
| }); | ||
| return letterHand | ||
| }, | ||
|
|
||
| usesAvailableLetters(input, lettersInHand) { | ||
| const lettersInHandCopy = Array.from(lettersInHand); | ||
| const inputArray = input.split(''); | ||
| let validHand = true | ||
| inputArray.forEach( function(char) { | ||
|
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 refactoring to a different type of loop so that you could return false as soon as it's encountered. |
||
| if (lettersInHandCopy.includes(char)) { | ||
| lettersInHandCopy.splice(lettersInHandCopy.indexOf(char), 1) | ||
| } else { validHand = false; | ||
| } | ||
| }); | ||
| return validHand | ||
| }, | ||
|
|
||
| highestScoreFrom(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. style note: even though it's not required, placing |
||
| let wordStats = words.map(x => ( { word: x, score: this.scoreWord(x) } )); | ||
|
|
||
| wordStats.sort(function (a, b) { | ||
| return b.score - a.score; | ||
| }); | ||
|
|
||
| let bestWord = wordStats[0]; | ||
|
|
||
| for (const element of wordStats) { | ||
| if (element.score === bestWord.score && element.word.length === 10) { | ||
| return element | ||
| } else if (element.score === bestWord.score && element.word.length < bestWord.word.length) { | ||
| bestWord = element | ||
| } | ||
| } | ||
| return bestWord | ||
| }, | ||
| }; | ||
|
|
||
| scoreWord(word) { | ||
| const scores = { | ||
| "AEIOULNRST": 1, | ||
| "DG": 2, | ||
| "BCMP": 3, | ||
| "FHVWY": 4, | ||
| "K": 5, | ||
| "JX": 8, | ||
| "QZ": 10 | ||
| } | ||
| const wordArray = word.toUpperCase().split(''); | ||
| let wordScore = 0; | ||
|
|
||
| wordArray.forEach( function(char) { | ||
| for (const key in scores) { | ||
| if (key.includes(char)) { | ||
| wordScore += scores[key]; | ||
| } | ||
| } | ||
| }); | ||
| if (wordArray.length > 6) { | ||
|
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.
|
||
| wordScore += 8; | ||
| } | ||
|
|
||
| return wordScore | ||
| } | ||
| } | ||
|
|
||
| // 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.
Style note: Consider giving each letters it's own line.