-
Notifications
You must be signed in to change notification settings - Fork 29
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
Ports - Elle & Sopheary #20
base: master
Are you sure you want to change the base?
Conversation
…ful testing with staarfish for troubleshooting. Next commit will clean that up for instructor review.
…with 0 errors and 0 fails.
AdagramsWhat We're Looking For
Hi Elle and Sopheary! Good work on this project! Your submitted code is good code style, and proves to me that the iteration and use of I have a few comments about some things like global variables and a helpful method to use in the future to make your code slimmer That being said, great work on this project overall! |
quantity.times do | ||
$letter_pool << letter.to_s | ||
end | ||
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.
You all populated a variable representing the letter pool as a global variable! In some ways, this makes sense, but in general, we'll avoid using global variables. Our hope was top put the above few lines within the draw_letters
method, since that's the only time you'll use this variable.
5 => ["K"], | ||
8 => ["J", "X"], | ||
10 => ["Q", "Z"], | ||
} |
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.
Similar to my previous comment: we'll try to avoid using global variables in the future, and the only method that uses this variable $letter_scores
is in the score_word
method, so we could move this variable there.
# Make a copy of the input array and keep the original | ||
# array unchanged. The original input needs to remain in tact so | ||
# that Ruby can continue to iterate through it the | ||
# uses_available_letters methods. |
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 is a great use of a comment: to add detail about something that feels a little weird and needs explanation!
break | ||
end | ||
hand_index += 1 | ||
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.
Nice use of each_with_index
! It seems to me that the purpose of this loop is to find the index of the letter you're looking for. There is a method that works on strings for this: letters_in_hand.index(letter)
... which will give you the first index of a matching element (letter
) in the array (letters_in_hand
). It's assuming to find the first index of a matching element, but you can safely make that assumption since you're iterating through input
in order :) (Actually, it kind of feels like you implemented the .index
method, so great job on that :D)
hand_index += 1 | ||
end | ||
|
||
letters_in_hand.delete_at(hand_index) |
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.
In conjunction with what I mentioned above, you could replace this line with: letters_in_hand.delete_at(letters_in_hand.index(letter))
break | ||
end | ||
end | ||
input_copy.delete_at(i) |
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 loop ends up solving a similar problem to above, and therefore, has a similar solution. With that, if you wanted to use the .index
method, you could replace this line with: input_copy.delete_at(input_copy.index(letter))
|
||
winning_word[:score] = max_score.to_i | ||
return winning_word | ||
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 method ended up being pretty long -- if methods get this long, feel free to break sections up into smaller helper methods
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerable
mixin? If so, where and why was it helpful?