Kay and Laura.rb#21
Open
lauracodecreations wants to merge 17 commits into
Open
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
|
CheezItMan
reviewed
Aug 23, 2018
| 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 ) |
| 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.
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.
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.
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.
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| |
| 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.
You have a loop and inside that you're sorting each iteration. This is a bit inefficient.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?