-
Notifications
You must be signed in to change notification settings - Fork 33
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
Branches - Xinran and Macaria #3
base: master
Are you sure you want to change the base?
Conversation
AdagramsWhat We're Looking For
Great work on this project, Xinran and Macaria! Your code is smooth, logical, readable, and has overall good code style. There are a few opportunities for refactoring on this if you had more time on this project, so I've added a few comments. That being said, your submission is great overall! Keep up the good work! |
index_of_letters.delete(index) | ||
end | ||
return letters_in_hand | ||
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.
If you had more time on this project to refactor, I think that there are some built in Ruby methods that could have made your solution a little bit shorter, such as shuffle
(so you could randomly shuffle letters_arr
and then delete off of letters_arr
, instead of relying on index_of_letters
so much.)
end | ||
|
||
# This method checks that the letters_in_hand contains the plucked letters from previous method | ||
def uses_available_letters? (input, letters_in_hand) |
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.
Minor nitpick: You CAN define a method with a space between the method name and the input parens, but Ruby will give a warning, because it prefers it if the method signature looks more like def uses_available_letters?(input, letters_in_hand)
input.split('').each do |tile| | ||
if letters_in_hand_copy.include?(tile) | ||
index_of_tile = letters_in_hand_copy.index(tile) | ||
letters_in_hand_copy.delete_at(index_of_tile) |
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.
Hm, in the above two lines, you find the index of tile
and store it at index_of_tile
, and then delete the element at that index of tile. Could we use the .delete
method to delete the first occurance of tile
's value? Replacing the above two lines with this line seems to work, and the tests still pass:
letters_in_hand_copy.delete(tile)
index_of_tile = letters_in_hand_copy.index(tile) | ||
letters_in_hand_copy.delete_at(index_of_tile) | ||
else | ||
return false |
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.
It's clever to return false
here, because this way the method exits as soon as you need to :)
end | ||
end | ||
shortest_word = highest_scores.min_by { |word| word.length } | ||
return {word: shortest_word, score: words_scores.keys.max} |
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.
Clever!
end | ||
|
||
# OPTIONAL METHOD: Reads from a dictionary csv to determine if input is a valid word or not. To run wave-5-game.rb must access file from adagrams directory. | ||
def is_in_english_dict?(input) |
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.
Fantastic work on the optional wave 5! This makes me happy!
end | ||
|
||
# OPTIONAL METHOD: Reads from a dictionary csv to determine if input is a valid word or not. To run wave-5-game.rb must access file from adagrams directory. | ||
def is_in_english_dict?(input) |
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.
Also... what about the tests? :)
|
||
# OPTIONAL METHOD: Reads from a dictionary csv to determine if input is a valid word or not. To run wave-5-game.rb must access file from adagrams directory. | ||
def is_in_english_dict?(input) | ||
return DICTIONARY.include?([input.downcase]) ? true : false |
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 a ternary! Let's keep pushing this refactor ;) Consider:
return DICTIONARY.include?([input.downcase])
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerable
mixin? If so, where and why was it helpful?