-
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
Leaves - Kristina and Julia #15
base: master
Are you sure you want to change the base?
Conversation
…c, and moving return statement
…hy the code wasn't working.
…mitting project now.
AdagramsWhat We're Looking For
|
letters_in_hand = [] | ||
|
||
10.times do |letter| | ||
letter = remaining_pool.sample |
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 is another version of sample! It might help you DRY up this code.
|
||
# Wave one method | ||
def draw_letters | ||
remaining_pool = %w(a a a a a a a a a b b c c d d d d e e e e e e e e e e e e f f g g g h h i i i i i i i i i j k l l l l m m n n n n n n o o o o o o o o p p q r r r r r r s s s s t t t t t t u u u u v v w w x y y 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.
Why do we redo the work of line 3 here?
|
||
|
||
# Wave 2: uses_available_letters? | ||
# Need to review lines 57-67, b/c failing test for returning true if the submitted letters are valid against the drawn letters |
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 comment should come out before submission!
|
||
input_array.each do |letter| | ||
unless letters_in_hand.include?(letter) | ||
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.
You end up repeating this work down below.
|
||
# making a hash from user_input with letters as keys and counts as values | ||
input_hash = {} | ||
input_array.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.
I think making a second hash complicates this a lot. What if you just used the input string to count down the number of letters from letters_hand_hash
?
end | ||
|
||
# If the length of word is between 7-10, add 8 points to the total score | ||
if input_array.length == 7 || input_array.length == 8 || input_array.length == 9 || input_array.length == 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.
You can reduce the amount of work you are doing here! It's possible to do this line with only 2 comparisons. What are they?
if input_array.length >= 7 && input_array.length <= 10
# Calculating the sum for all the letters in word | ||
sum = 0 | ||
scores.each do |score| | ||
sum = sum + 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.
If you're trying to end up with a sum, why make an array and then convert that array into a bunch of letters? You can just add up all the letter scores as you go!
|
||
words.each do |word| | ||
word_letters = word.chars #convert string to array of characters | ||
word_length = word_letters.length #count the length of characters |
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 added a step here. word.length
is a valid string operation!
|
||
# determine which word has the highest score and return associated word | ||
highest_score = word_scores.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.
You currently have 2 failing tests. The code that will fix them goes here. You need to either 1) prefer the shortest word or 2) prefer the word that uses all 10 letters, depending on input.
@@ -0,0 +1,174 @@ | |||
require 'pry' | |||
|
|||
letter_pool = %w(a a a a a a a a a b b c c d d d d e e e e e e e e e e e e f f g g g h h i i i i i i i i i j k l l l l m m n n n n n n o o o o o o o o p p q r r r r r r s s s s t t t t t t u u u u v v w w x y y 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.
looks like you have two versions of this file. was that intentional?
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerable
mixin? If so, where and why was it helpful?