-
Notifications
You must be signed in to change notification settings - Fork 27
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
Kay and Laura.rb #21
base: master
Are you sure you want to change the base?
Kay and Laura.rb #21
Conversation
…ictionary word, failing test that previously was passed in wave 4--testing merge previously passing code with current buggy code
AdagramsWhat We're Looking For
|
def draw_letters | ||
|
||
# all letters | ||
letters = %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.
Good data structure to use!
10.times do | ||
# check if index is in indices_used array , if true generate new random index | ||
while indices_used.include?(index) | ||
index = Random.rand(min..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.
Just a note, this loop could potentially go a long time. You would do better to remove an element once you've selected it.
result << true | ||
else | ||
# user used a letter that does not exists | ||
result << 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.
Maybe you should just return false
.
input.each_char do |letter| | ||
# check if letter exists in letters_in_han | ||
if letters_in_hand.include?(letter) | ||
result << true |
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.
What if a letter appears twice in input
, but not in letters_in_hand
end | ||
final_results << result.all? { |value| value == true} | ||
|
||
input.each_char 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.
This seems to be doing what the above did, but better. Avoid duplication of effort.
group4 = %w(F H V W Y) | ||
group5 = %w(J X) | ||
group6 = %w(Q Z) | ||
word.upcase.each_char 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.
👍
score = data.select{ |k, v| k == winner}.values[0] | ||
return {:word => winner, :score => score} | ||
else # select shortest word and return it as a winner | ||
winner = ties_words.sort_by {|x| x.length}.first |
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 have a loop and inside that you're sorting each iteration. This is a bit inefficient.
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerable
mixin? If so, where and why was it helpful?