-
Notifications
You must be signed in to change notification settings - Fork 36
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
adagrams #4
base: master
Are you sure you want to change the base?
adagrams #4
Conversation
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.
Well done Aimee & Ida. You hit the learning goals here. I like the use of Enumerable methods here. It's quite well done and very compact.
@@ -0,0 +1,139 @@ | |||
# frozen_string_literal: true | |||
|
|||
a = Array.new(9) { 'A' } |
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.
This method works, but it's pretty long-hand.
ALPHABET = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, | ||
o, p, q, r, s, t, u, v, w, x, y, z].flatten | ||
|
||
SCORE_CHART = [ | ||
{ 1 => %w[A E I O U L N R S T] }, | ||
{ 2 => %w[D G] }, | ||
{ 3 => %w[B C M P] }, | ||
{ 4 => %w[F H V W Y] }, | ||
{ 5 => %w[K] }, | ||
{ 8 => %w[J X] }, | ||
{ 10 => %w[Q Z] } | ||
].freeze |
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.
I like how you included these constants at the top for reference.
# wave 1 | ||
def draw_letters | ||
ten_letters = ALPHABET.sample(10) | ||
return ten_letters | ||
end |
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.
👍
count = letter_frequency[letter] | ||
count += 1 | ||
letter_frequency[letter] = count |
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.
A little simplification.
count = letter_frequency[letter] | |
count += 1 | |
letter_frequency[letter] = count | |
letter_frequency[letter] += 1 |
count = letter_count[letter] | ||
if count == 0 | ||
false | ||
else | ||
count -= 1 | ||
letter_count[letter] = count | ||
true | ||
end |
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.
This works, but you can simplify it a bit.
count = letter_count[letter] | |
if count == 0 | |
false | |
else | |
count -= 1 | |
letter_count[letter] = count | |
true | |
end | |
letter_count[letter] -= 1 | |
letter_count[letter] < 0 |
end | ||
|
||
# wave 3 | ||
def score_word(word) |
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.
👍
Really clever use of select
, and include?
.
# wave 4 | ||
def highest_score_from(words) |
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.
👍
Assignment Submission: Adagrams
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection
Enumerable
mixin? If so, where and why was it helpful?