-
Couldn't load subscription status.
- Fork 29
Sockets - Kelly and Pauline #19
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
| scored_words << {:word => word, :score => score_word(word)} | ||
| end | ||
|
|
||
| highest_scored_word = scored_words.max_by do |scored_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.
scored_words here does a weird thing to your scored_words from line 93. Make sure to check your error messages before you submit your code! https://en.wikipedia.org/wiki/Variable_shadowing
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 could easily avoid this by calling the line thusly:
highest_scored_word = scored_words.max_by do |word|| end | ||
|
|
||
| if highest_score_array.length > 1 | ||
| highest_scored_word = highest_score_array.min_by { |words| words[:word].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.
again, this words variable is shadowing something. This one not causing any harm, but it CAN do really weird and bad stuff. In the same scope, try to use unique names.
| letter_pool = make_letter_pool(letter_pool, "H", 2) | ||
| letter_pool = make_letter_pool(letter_pool, "I", 9) | ||
| letter_pool = make_letter_pool(letter_pool, "J", 1) | ||
| letter_pool = make_letter_pool(letter_pool, "K", 1) |
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 don't think this formatting makes this any easier to read. This takes up more space than a loop would have, and more space than hard-coding an array would have.
| 10.times do | ||
| curr_letter = letter_pool.sample | ||
| user_hand.push(curr_letter) | ||
| available_letters.delete(curr_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 letter generation method will never result in duplicate letters, because the .delete method deletes all of the curr_letter in the array.
| input_letters = input.chars | ||
| input_letters.each do |letter| | ||
| if letters_in_hand.include?(letter) | ||
| letters_in_hand.delete(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 never got caught because of draw letters, but this code would break for sets with duplicate letters, because .delete removes duplicates.
AdagramsWhat We're Looking For
|
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?