Leaves - Samantha#30
Open
iamsammysam wants to merge 6 commits into
Open
Conversation
| const Adagrams = { | ||
| drawLetters() { | ||
| // Implement this method for wave 1 | ||
| const alphabet = 'AAAAAAAAABBCCDDDDEEEEEEEEEEEEFFGGGHHIJKLLLLMMNNNNNNOOOOOOOOPPQRRRRRRSSSSTTTTTTUUUUVVWWXYYZ'; |
There was a problem hiding this comment.
This data structure works, but it's not very DRY and would be tricky to change. For example, suppose I said you had the wrong number of "I"s - you would have to do a lot of counting to solve the problem.
Instead you might store a hash of letter frequencies like this
letterQuantities: {
A: 9, B: 2, ...
}
| const alphabet = 'AAAAAAAAABBCCDDDDEEEEEEEEEEEEFFGGGHHIJKLLLLMMNNNNNNOOOOOOOOPPQRRRRRRSSSSTTTTTTUUUUVVWWXYYZ'; | ||
| const lettersInHand = []; | ||
|
|
||
| for (let i = 0; i < 10; i++) { |
There was a problem hiding this comment.
There's a small bug here. Consider how you could make sure you don't pick the same letter 10 times (however unlikely it is).
|
|
||
| for (let i = 0; i < (input.length); i++) { | ||
| if (lettersInHand.includes(input[i]) === false) { | ||
| result = false; |
There was a problem hiding this comment.
since you used a traditional for loop you could simply return false here so you don't unnecessarily need to go through the whole loop.
| }, | ||
|
|
||
| scoreWord(word) { | ||
| const score = { A:1, E:1, I:1, O:1, U:1, L:1, N:1, R:1, S:1, T:1, D:2, G:2, |
There was a problem hiding this comment.
style note: put each key-value pair on one line.
| // The function indexOf finds the value for the index with the max value | ||
| let correct = { word: words[scores.indexOf(Math.max.apply(null, scores))], score: Math.max.apply(null, scores) }; | ||
|
|
||
| // Still need to work on the tie-breaking rules for Wave 4: |
JS AdagramsWhat We're Looking For
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JS Adagrams
Congratulations! You're submitting your assignment!
Comprehension Questions