-
Couldn't load subscription status.
- Fork 29
Sockets: Shubha & Grace #4
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
base: master
Are you sure you want to change the base?
Conversation
…ing tests to spec file
AdagramsWhat We're Looking For
|
| } | ||
|
|
||
| avail_letters = array_gen(letter_freq) | ||
| used_letters = avail_letters.sample(10) |
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 lovely! I can see everything I need to see about how this works, and if I get confused about array_gen it's close at hand!
| end | ||
| if input.length > letters_in_hand.length | ||
| return false | ||
| else |
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.
Small semantic note: If you don't return above or raise, then you won't hit the code in this else anyway. In cases like this, it's nice to leave the meat of the method outside of an else block.
| possible_letters = letters_in_hand.clone | ||
| input.upcase.split(//).each do |char| | ||
| if possible_letters.include?(char) | ||
| possible_letters.delete(char) |
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 will never return true for a word with a repeated letter. For example,
ruby hand = ["E", "F", "R", "A", "E", "L", "V", "A", "D", "K"] uses_available_letters?("ADA", hand) # => false
The reason why is that Ruby's Array#delete method will remove all matching elements from an array, not just the first match.
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.
Good to know!
If we were to write something like:
i = index (char)
possible_letters.delete_at(i)
would it preserve the other repeats of the letter?
And is there a more elegant way of doing it?
| if possible_letters.include?(char) | ||
| possible_letters.delete(char) | ||
| 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.
Nice work returning when you have the answer!
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?