-
Couldn't load subscription status.
- Fork 29
Sockets - Hana && Nara #14
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
AdagramsWhat We're Looking For
|
| letters_in_hand.each_with_index do |letter, index| | ||
| if input_array.include?(letter) | ||
| size += 1 | ||
| letters_in_hand.delete(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.
Because you delete letters from the hand as you go if a user submits a mostly correct word the letters it used are deleted. For example:
$ ruby wave-2-game.rb
Welcome to Adagrams!
Let's draw 10 letters from the letter pool...
You have drawn the letters:
t, g, e, a, a, s, e, e, a, e
Please input a word that only uses the letters from the letter bank
tget
You entered in a word that contains characters not in the letter bank
Please input a word that only uses the letters from the letter bank
tge
You entered in a word that contains characters not in the letter bank
Please input a word that only uses the letters from the letter bank
|
|
||
| def score_word(word) | ||
| points = 0 | ||
| word.upcase.split(//).each do |letter| |
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.
There's a handy .chars method on String that does the same thing as .split(//) but a little clearer, if you want to do this again in the future. 😃
| elsif word.length < min_length | ||
| min_length = word.length | ||
| best_word[:word] = word | ||
| best_word[:score] = max_words[:score] |
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 clever way to find the shortest word in max_words.
| end | ||
|
|
||
| def highest_score_from(words) | ||
| highest_score = Hash.new(0) |
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.
Misleading variable name: highest_score winds up holding all of the scores, not just the highest one(s).
|
|
||
| def uses_available_letters?(input, letters_in_hand) | ||
| size = 0 | ||
| input_array = input.upcase.split(//) |
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.
Calling upcase on the user's input is a good idea, however you forgot to call upcase on the letters in letters_in_hand which means that if you are passed lowercase letters you won't have any matches.
You could add this to fix it:
letters_in_hand = letters_in_hand.map { |l| l.upcase }| input_array = input.upcase.split(//) | ||
|
|
||
| letters_in_hand.each_with_index do |letter, index| | ||
| if input_array.include?(letter) |
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 really close to right. Because of the way the above loop is implemented this winds up requiring the user to use all of a given letter. If you input_array.each and letters_in_hand.include? then this works perfectly.
| end | ||
| end | ||
|
|
||
| if size == input_array.length |
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 having to keep track of size is a little awkward.
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?