Leaves - Katie and Dominique#18
Conversation
AdagramsWhat We're Looking For
|
| sum = 0 | ||
| total_sum = 0 | ||
|
|
||
| score_hash = {1=> ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], 2=> ["D", "G"], |
There was a problem hiding this comment.
An alternative approach would be to store the letter scores in a hash, something like this:
LETTER_SCORES = {
"A" => 1
"B" => 3,
"C" => 3,
"D" => 2,
# ...
}Then to get the score for a letter, you can say LETTER_SCORES[letter].
You could create this hash from your original array of hashes raw_tiles
Organizing the data this way would simplify the logic below.
| # Return word and score of word with highest score | ||
| def highest_score_from(words) | ||
| high_score_hash = {word: "", score: 0} | ||
| high_score = 0 |
There was a problem hiding this comment.
We reworked the logic for this method and you don't end up using high_score and high_score_length. Rake provided this warning for you:
/Users/becca/Documents/GitHub/c12/adagrams/lib/adagrams.rb:90: warning: assigned but unused variable - high_score
/Users/becca/Documents/GitHub/c12/adagrams/lib/adagrams.rb:91: warning: assigned but unused variable - high_score_length
/Users/becca/Documents/GitHub/c12/adagrams/lib/adagrams.rb:46: warning: assigned but unused variable - letters_in_hand
You should remove these variables from your code.
| return word1 | ||
| end | ||
|
|
||
|
|
There was a problem hiding this comment.
For the sake of cleanliness, remove these extra lines.
|
|
||
| tile_set = [] | ||
|
|
||
| # extracts letter and score keys and puts them in array called raw_tiles |
There was a problem hiding this comment.
Clever use of the data structure you created. Consider also how you could use a data structure organized like this: {"A"=>9, "B"=>2,...}
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?