Leaves Morgan & Janice#11
Conversation
AdagramsWhat We're Looking For
|
| require 'csv' | ||
|
|
||
| def draw_letters | ||
| all_letters_hash = { |
There was a problem hiding this comment.
Consider making this hash a global variable assigned outside the method so that it can be used other place.
| all_letters_array << letter | ||
| end | ||
| end | ||
| letters_in_hand = all_letters_array.sample(10) |
There was a problem hiding this comment.
You should explicitly return letters_in_hand. Note warning when you run rake:
"/Users/becca/Documents/GitHub/c12/adagrams/lib/adagrams.rb:38: warning: assigned but unused variable - letters_in_hand"
| letter_count[letter] -= 1 | ||
| if letter_count[letter] < 0 | ||
| return false | ||
| break |
There was a problem hiding this comment.
You don't need break. When you return in a function, nothing is executed after the return.
|
|
||
| def score_word(word) | ||
| # Make new hash to store letters and point values | ||
| points = { |
There was a problem hiding this comment.
Similar to all_letter_hash, it would make sense to define this hash outside the method as a global variable using all caps.
| if input_array.size >= 7 && input_array.size < 11 | ||
| return total_points.sum + 8 | ||
| end | ||
| # if total_points.empty? |
There was a problem hiding this comment.
Remove unused commented code when you refactor.
| return total_points.sum | ||
| end | ||
|
|
||
| # REPLACE HIGH SCORE HASH STEPS WITH A HELPER METHOD |
There was a problem hiding this comment.
This would be a great use of a helper method, and a good task for a refactor.
| end | ||
|
|
||
| # REPLACE HIGH SCORE HASH STEPS WITH A HELPER METHOD | ||
| def highest_score_from(words) |
There was a problem hiding this comment.
The comments in this method are helpful and are an example of a good use of comments.
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
def+ method signature (name and parameters) + code block +end.Enumerablemixin? If so, where and why was it helpful?.mapto convert letters into their corresponding points. It enabled us to alter the original array elegantly and without creating a hash at that point.putsstatements.