Conversation
| require "csv" | ||
|
|
||
| def draw_letters() | ||
| letter_pool = ["A"] * 9 + ["B"] * 2 + ["C"] * 2 + ["D"] * 4 + ["E"] * 12 + ["F"] * 2 + ["G"] * 3 + ["H"] * 2 + ["I"] * 9 + ["J"] + ["K"] + ["L"] * 4 + ["M"] * 2 + ["N"] * 6 + ["O"] * 8 + ["P"] * 2 + ["Q"] + ["R"] * 6 + ["S"] * 4 + ["T"] * 6 + ["U"] * 4 + ["V"] * 2 + ["W"] * 2 + ["X"] + ["Y"] * 2 + ["Z"] |
There was a problem hiding this comment.
Consider using a data structure to store the letter distribution information. You can then use this data structure to create your array.
letter_counts = {"A"=>9, "B"=>2,...}| def score_word(word) | ||
| word_arr = word.upcase.split("") | ||
| points = 0 | ||
| word_arr.each do |letter| |
There was a problem hiding this comment.
While this case statement works, it means that the information about which letter has which score is locked into this piece of code, and can't easily be used elsewhere. For example, if you wanted to display the value of each letter in a hand, you would need to repeat this work.
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].
| word_score << { word: word, score: score_word(word) } | ||
| end | ||
|
|
||
| max = word_score.max_by { |element| element[:score] }[:score] |
There was a problem hiding this comment.
You've packed lots of logic in a few lines of elegant code. Consider adding a few comments that outline the rules for determining the winner, particularly the tiebreaker logic.
AdagramsWhat We're Looking For
I'm making a few comments on this assignment about some suggestions on how to refactor, but they are all optional ways of looking at this code again. Overall, you two have done a great job. Good work! |
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?