From d1cb985553b4f1bfeb7951a91d92eef5de3eee3f Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Mon, 12 Aug 2019 15:13:15 -0700 Subject: [PATCH 1/9] method for draw_letters created, ARRAY_OF_LETTERS created, so far it works --- lib/adagrams.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..5b9328e 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,9 @@ +def draw_letters + sample_letters = ARRAY_OF_LETTERS.shuffle.pop(10) + return sample_letters +end + + +ARRAY_OF_LETTERS = ["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"] + +p draw_letters From f2a9842ed9e615271eff19d90771eca891f9b28d Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Mon, 12 Aug 2019 16:34:21 -0700 Subject: [PATCH 2/9] created uses_available_letters? method that checks to see if the user entered word is made of letters in their hand. --- lib/adagrams.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 5b9328e..65a19b8 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,9 +1,23 @@ def draw_letters - sample_letters = ARRAY_OF_LETTERS.shuffle.pop(10) - return sample_letters + letters_in_hand = ARRAY_OF_LETTERS.shuffle.pop(10) + return letters_in_hand end ARRAY_OF_LETTERS = ["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"] -p draw_letters + + +def uses_available_letters? (input, letters_in_hand) + input = input.upcase.chars + #p input + check = 0 + input.each do |chars| + if letters_in_hand.include?(chars) + letters_in_hand.delete(chars) + else + check += 1 + end + return check == 0 + end +end From eaa83ffeb920e755da547afaf599de4dcbdfe6b7 Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Tue, 13 Aug 2019 16:25:29 -0700 Subject: [PATCH 3/9] reimplemented check for test 002 returns false word contains letters not in the drawn letters to pass appropriately, test 003 still failing, have not written method for it yet. --- lib/adagrams.rb | 12 +++--- test/adagrams_test.rb | 86 +++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 65a19b8..9785714 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,23 +1,23 @@ +require 'pry' + + def draw_letters - letters_in_hand = ARRAY_OF_LETTERS.shuffle.pop(10) + letters_in_hand = ARRAY_OF_LETTERS.shuffle.slice(1..10) return letters_in_hand end - ARRAY_OF_LETTERS = ["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"] - - def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars #p input check = 0 input.each do |chars| if letters_in_hand.include?(chars) - letters_in_hand.delete(chars) + check = 0 else check += 1 end - return check == 0 end + return check == 0 end diff --git a/test/adagrams_test.rb b/test/adagrams_test.rb index 90ec44d..4d1348a 100644 --- a/test/adagrams_test.rb +++ b/test/adagrams_test.rb @@ -13,11 +13,11 @@ drawn_letters = draw_letters expect(drawn_letters.size).must_equal 10 end - + it 'returns an array, and each item is a single-letter string' do drawn_letters = draw_letters expect(drawn_letters.size).must_equal 10 - + expect(drawn_letters).must_be_instance_of Array drawn_letters.each do |letter| expect(letter).must_be_instance_of String @@ -25,155 +25,155 @@ end end end - + describe 'uses_available_letters? method' do - + it 'returns true if the submitted letters are valid against the drawn letters' do drawn_letters = ['D', 'O', 'G', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] test_word = 'DOG' - + is_valid = uses_available_letters? test_word, drawn_letters - + expect(is_valid).must_equal true end - + it 'returns false word contains letters not in the drawn letters' do drawn_letters = ['D', 'O', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] test_word = 'DOG' - + is_valid = uses_available_letters? test_word, drawn_letters - + expect(is_valid).must_equal false end - + it 'returns false word contains repeated letters more than in the drawn letters' do drawn_letters = ['A', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] test_word = 'AAA' - + is_valid = uses_available_letters? test_word, drawn_letters - + expect(is_valid).must_equal false end - + it 'does not change the letters in hand' do drawn_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] dl_copy = drawn_letters.dup - + # Hint: if your implementation of uses_available_letters? # needs to change the hand, you should make a copy first uses_available_letters? 'ABCD', drawn_letters - + expect(drawn_letters).must_equal dl_copy end end - + describe 'score_word method' do it 'returns an accurate numerical score according to the score chart' do expect(score_word("A")).must_equal 1 expect(score_word("DOG")).must_equal 5 expect(score_word("WHIMSY")).must_equal 17 end - + it 'returns a score regardless of input case' do expect(score_word("a")).must_equal 1 expect(score_word("dog")).must_equal 5 expect(score_word("wHiMsY")).must_equal 17 end - + it 'returns a score of 0 if given an empty input' do expect(score_word("")).must_equal 0 end - + it 'adds an extra 8 points if the word is 7 or more characters long' do expect(score_word("XXXXXXX")).must_equal 64 expect(score_word("XXXXXXXX")).must_equal 72 expect(score_word("XXXXXXXXX")).must_equal 80 end end - + describe 'highest_score_from method' do it 'returns a hash that contains the word and score of best word in an array' do words = ['X', 'XX', 'XXX', 'XXXX'] best_word = highest_score_from words - + expect(best_word[:word]).must_equal 'XXXX' expect(best_word[:score]).must_equal 32 end - + it 'accurately finds best scoring word even if not sorted' do words = ['XXX', 'XXXX', 'XX', 'X'] best_word = highest_score_from words - + expect(best_word[:word]).must_equal 'XXXX' expect(best_word[:score]).must_equal 32 end - + it 'in case of tied score, prefers the word with fewer letters' do # the character 'M' is worth 3 points, 'W' is 4 points words = ['MMMM', 'WWW'] - + # verify both have a score of 12 expect(score_word(words.first)).must_equal 12 expect(score_word(words.last)).must_equal 12 - + best_word = highest_score_from words - + expect(best_word[:word]).must_equal 'WWW' expect(best_word[:score]).must_equal 12 end - + it 'in case of tied score, prefers the word with fewer letters regardless of order' do # the character 'M' is worth 3 points, 'W' is 4 points words = ['WWW', 'MMMM'] - + # verify both have a score of 12 expect(score_word(words.first)).must_equal 12 expect(score_word(words.last)).must_equal 12 - + best_word = highest_score_from words - + expect(best_word[:word]).must_equal 'WWW' expect(best_word[:score]).must_equal 12 end - + it 'in case of tied score, prefers most the word with 10 letters' do # the character 'A' is worth 1 point, 'B' is 3 points words = ['AAAAAAAAAA', 'BBBBBB'] - + # verify both have a score of 10 expect(score_word(words.first)).must_equal 18 expect(score_word(words.last)).must_equal 18 - + best_word = highest_score_from words - + expect(best_word[:word]).must_equal 'AAAAAAAAAA' expect(best_word[:score]).must_equal 18 end - + it 'in case of tied score, prefers most the word with 10 letters regardless of order' do # the character 'A' is worth 1 point, 'B' is 3 points words = ['BBBBBB', 'AAAAAAAAAA'] - + # verify both have a score of 10 expect(score_word(words.first)).must_equal 18 expect(score_word(words.last)).must_equal 18 - + best_word = highest_score_from words - + expect(best_word[:word]).must_equal 'AAAAAAAAAA' expect(best_word[:score]).must_equal 18 end - + it 'in case of tied score and same length words, prefers the first word' do # the character 'A' is worth 1 point, 'E' is 1 point words = ['AAAAAAAAAA', 'EEEEEEEEEE'] - + # verify both have a score of 10 expect(score_word(words.first)).must_equal 18 expect(score_word(words.last)).must_equal 18 - + best_word = highest_score_from words - + expect(best_word[:word]).must_equal words.first expect(best_word[:score]).must_equal 18 end From be2e0123588e0ba549bcd51b46be07ac19d57751 Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Tue, 13 Aug 2019 16:44:59 -0700 Subject: [PATCH 4/9] created score word method and tested it, it works, good job everyone --- lib/adagrams.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 9785714..e2160a8 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -21,3 +21,15 @@ def uses_available_letters? (input, letters_in_hand) end return check == 0 end + +def score_word(word) + letter_points = { + "A" => 1, "B" => 3, "C" => 3, "D" => 2, "E" => 1, "F" => 4, "G" => 2, "H" => 4, "I" => 1, "J" => 8, "K" => 5, "L" => 1, "M" => 3, "N" => 1, "O" => 1, "P" => 3, "Q"=> 10, "R"=> 1, "S" => 1, "T" => 1, "U" => 1, "V" => 4, "W" => 4, "X" => 8, "Y" => 4, "Z" => 10 + } + word_array = word.upcase.chars + word_points = word_array.map do |k, v| + letter_points[k] + end + total_points = word_points.sum + return total_points +end \ No newline at end of file From 9c7d4fdcd5cbb1504140b45563678fa89b1c5b5b Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Wed, 14 Aug 2019 13:57:10 -0700 Subject: [PATCH 5/9] added to uses_available_letters? method to make sure noduplicate letters are used that aren't in the letters_in_hand_array, tested and works. --- lib/adagrams.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e2160a8..347e5c7 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -8,9 +8,29 @@ def draw_letters ARRAY_OF_LETTERS = ["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"] +# def duplicate_check (input, letters_in_hand) +# dup_input = input + +# dup_input.each do |chars| +# letters_in_hand.delete(chars) +# end +# p letters_in_hand +# end + + def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars - #p input + dup_letters_in_hand = letters_in_hand.clone + + input.each do |chars| + if dup_letters_in_hand.include?(chars) + dup_letters_in_hand.delete(chars) + else + raise ArgumentError, "Cannot use letters not in hand" + end + end + + check = 0 input.each do |chars| if letters_in_hand.include?(chars) @@ -19,9 +39,11 @@ def uses_available_letters? (input, letters_in_hand) check += 1 end end + # duplicate_check(input, letters_in_hand) return check == 0 end + def score_word(word) letter_points = { "A" => 1, "B" => 3, "C" => 3, "D" => 2, "E" => 1, "F" => 4, "G" => 2, "H" => 4, "I" => 1, "J" => 8, "K" => 5, "L" => 1, "M" => 3, "N" => 1, "O" => 1, "P" => 3, "Q"=> 10, "R"=> 1, "S" => 1, "T" => 1, "U" => 1, "V" => 4, "W" => 4, "X" => 8, "Y" => 4, "Z" => 10 @@ -31,5 +53,8 @@ def score_word(word) letter_points[k] end total_points = word_points.sum + if word.length > 6 && word.length < 11 + total_points += 8 + end return total_points end \ No newline at end of file From a200a16676c82b9334f8561b9a8f715215a089b7 Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Wed, 14 Aug 2019 16:06:24 -0700 Subject: [PATCH 6/9] created the tiebreaker_length to determine which word wins if there is a tie --- lib/adagrams.rb | 132 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 347e5c7..23a8749 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -57,4 +57,134 @@ def score_word(word) total_points += 8 end return total_points -end \ No newline at end of file +end + +# def highest_score_from(words) +# highest_score_hash = { +# word: words +# } +# words.each do |object| +# score = score_word(object) +# highest_score_hash[:score => score] +# end +# p highest_score_hash +# end + +def highest_score_from(words) + highest_score_hash = { + + } + score = 0 + winning_word = "" + # tie_breaker_words = [] + words.each do |object| + word_score = score_word(object) + if word_score > score + score = word_score + winning_word = object + # elsif word_score = score + # word_length = object.chars.length + # winning_word_length = winning_word.chars.length + # if word_length < winning_word_length + # winning_word = object + # elsif word_length == 10 + # winning_word = object + # elsif winning_word_length == 10 + # winning_word + # end + # end + + # tie_breaker_words>> winning_word + # tie_breaker_words>> object + elsif word_score = score + winning_word = tiebreaker_length(winning_word, object) + + end + # p winning_word + # p score + + highest_score_hash[:word] = winning_word + highest_score_hash[:score] = score + + + + + + # highest_score_hash[:score => score] + # end + # p highest_score_hash + end + return highest_score_hash +end + +def tiebreaker_length (old_word, new_word) + p old_word + p new_word + tiebreaker_len_arr = [old_word, new_word] + tiebreaker_len_arr.min { |old_word, new_word| old_word.length <=> new_word.length } +end + + + + + + + + + + + + + + + + + +# def highest_score_from(words) +# highest_score_hash = { + +# } +# score = 0 +# winning_word = "" +# # tie_breaker_words = [] +# words.each do |object| +# word_score = score_word(object) +# if word_score > score +# score = word_score +# winning_word = object +# # elsif word_score = score +# # word_length = object.chars.length +# # winning_word_length = winning_word.chars.length +# # if word_length < winning_word_length +# # winning_word = object +# # elsif word_length == 10 +# # winning_word = object +# # elsif winning_word_length == 10 +# # winning_word +# # end +# # end + +# # tie_breaker_words>> winning_word +# # tie_breaker_words>> object +# elsif word_score = score +# winning_word = tiebreaker_length(winning_word, object) +# else +# score +# end + +# highest_score_hash[:word] = winning_word +# highest_score_hash[:score] = score + +# return highest_score_hash +# # highest_score_hash[:score => score] +# # end +# # p highest_score_hash +# end + + +# def tiebreaker_length (old_word, new_word) +# tiebreaker_len_arr = [old_word, new_word] +# tiebreaker_len_arr.min { |old_word, new_word| old_word.length <=> new_word.length} + +# end + From 6045a7809e34b62a54a72e9a222e9644e1a1ed17 Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Wed, 14 Aug 2019 16:53:14 -0700 Subject: [PATCH 7/9] worked on tiebreaker, it works, now focusing on ten letters in tiebreaker --- lib/adagrams.rb | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 23a8749..c09448d 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -22,11 +22,14 @@ def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars dup_letters_in_hand = letters_in_hand.clone + input.each do |chars| + if dup_letters_in_hand.include?(chars) dup_letters_in_hand.delete(chars) else - raise ArgumentError, "Cannot use letters not in hand" + #raise ArgumentError, "Cannot use letters not in hand" + return false end end @@ -71,14 +74,18 @@ def score_word(word) # end def highest_score_from(words) - highest_score_hash = { - - } + highest_score_hash = {} score = 0 winning_word = "" # tie_breaker_words = [] words.each do |object| word_score = score_word(object) + length_of_obj = object.length + + # if length_of_obj == 10 + # winning_word = object + + if word_score > score score = word_score winning_word = object @@ -96,9 +103,15 @@ def highest_score_from(words) # tie_breaker_words>> winning_word # tie_breaker_words>> object - elsif word_score = score + elsif word_score == score + # length_of_obj = object.length + # length_of_winning_word = winning_word.length + # if length_of_obj = 10 + # winning_word = object + winning_word = tiebreaker_length(winning_word, object) + end # p winning_word # p score @@ -118,8 +131,8 @@ def highest_score_from(words) end def tiebreaker_length (old_word, new_word) - p old_word - p new_word + #p old_word + #p new_word tiebreaker_len_arr = [old_word, new_word] tiebreaker_len_arr.min { |old_word, new_word| old_word.length <=> new_word.length } end From 87a207f6e680637cbcdda81c7c1ab5c6b336f673 Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Wed, 14 Aug 2019 22:02:18 -0700 Subject: [PATCH 8/9] fixed the tiebreaker to take into accout if one of the words in the tie has 10 letters then it wins over the other. --- lib/adagrams.rb | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index c09448d..cc99702 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -80,7 +80,7 @@ def highest_score_from(words) # tie_breaker_words = [] words.each do |object| word_score = score_word(object) - length_of_obj = object.length + # length_of_obj = object.length # if length_of_obj == 10 # winning_word = object @@ -104,13 +104,16 @@ def highest_score_from(words) # tie_breaker_words>> winning_word # tie_breaker_words>> object elsif word_score == score - # length_of_obj = object.length - # length_of_winning_word = winning_word.length - # if length_of_obj = 10 - # winning_word = object - - winning_word = tiebreaker_length(winning_word, object) - + length_of_obj = object.length + length_of_winning_word = winning_word.length + if length_of_winning_word == 10 + winning_word = winning_word + elsif length_of_obj == 10 + winning_word = object + else + winning_word = tiebreaker_length(winning_word, object) + + end end # p winning_word @@ -131,11 +134,20 @@ def highest_score_from(words) end def tiebreaker_length (old_word, new_word) + # length_old = old_word.length + # length_new = new_word.length + # #if length_old == length_new + # if length_new == 10 + # winning_word = new_word + # if length_old == 10 + # winning_word = old_word + # end #p old_word #p new_word tiebreaker_len_arr = [old_word, new_word] tiebreaker_len_arr.min { |old_word, new_word| old_word.length <=> new_word.length } end +#end From 411ff2c5268442e9e3d4c20a24a0285edf6b74b6 Mon Sep 17 00:00:00 2001 From: Elizabeth Northrop Date: Thu, 15 Aug 2019 13:15:58 -0700 Subject: [PATCH 9/9] erased all comments --- lib/adagrams.rb | 141 ++---------------------------------------------- 1 file changed, 3 insertions(+), 138 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index cc99702..8b96471 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -8,32 +8,19 @@ def draw_letters ARRAY_OF_LETTERS = ["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"] -# def duplicate_check (input, letters_in_hand) -# dup_input = input - -# dup_input.each do |chars| -# letters_in_hand.delete(chars) -# end -# p letters_in_hand -# end - - def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars dup_letters_in_hand = letters_in_hand.clone input.each do |chars| - if dup_letters_in_hand.include?(chars) dup_letters_in_hand.delete(chars) else - #raise ArgumentError, "Cannot use letters not in hand" return false end end - check = 0 input.each do |chars| if letters_in_hand.include?(chars) @@ -42,11 +29,9 @@ def uses_available_letters? (input, letters_in_hand) check += 1 end end - # duplicate_check(input, letters_in_hand) return check == 0 end - def score_word(word) letter_points = { "A" => 1, "B" => 3, "C" => 3, "D" => 2, "E" => 1, "F" => 4, "G" => 2, "H" => 4, "I" => 1, "J" => 8, "K" => 5, "L" => 1, "M" => 3, "N" => 1, "O" => 1, "P" => 3, "Q"=> 10, "R"=> 1, "S" => 1, "T" => 1, "U" => 1, "V" => 4, "W" => 4, "X" => 8, "Y" => 4, "Z" => 10 @@ -62,47 +47,16 @@ def score_word(word) return total_points end -# def highest_score_from(words) -# highest_score_hash = { -# word: words -# } -# words.each do |object| -# score = score_word(object) -# highest_score_hash[:score => score] -# end -# p highest_score_hash -# end - def highest_score_from(words) highest_score_hash = {} score = 0 winning_word = "" - # tie_breaker_words = [] + words.each do |object| word_score = score_word(object) - # length_of_obj = object.length - - # if length_of_obj == 10 - # winning_word = object - - if word_score > score score = word_score winning_word = object - # elsif word_score = score - # word_length = object.chars.length - # winning_word_length = winning_word.chars.length - # if word_length < winning_word_length - # winning_word = object - # elsif word_length == 10 - # winning_word = object - # elsif winning_word_length == 10 - # winning_word - # end - # end - - # tie_breaker_words>> winning_word - # tie_breaker_words>> object elsif word_score == score length_of_obj = object.length length_of_winning_word = winning_word.length @@ -112,104 +66,15 @@ def highest_score_from(words) winning_word = object else winning_word = tiebreaker_length(winning_word, object) - - end - + end end - # p winning_word - # p score - highest_score_hash[:word] = winning_word highest_score_hash[:score] = score - - - - - - # highest_score_hash[:score => score] - # end - # p highest_score_hash end return highest_score_hash end def tiebreaker_length (old_word, new_word) - # length_old = old_word.length - # length_new = new_word.length - # #if length_old == length_new - # if length_new == 10 - # winning_word = new_word - # if length_old == 10 - # winning_word = old_word - # end - #p old_word - #p new_word tiebreaker_len_arr = [old_word, new_word] tiebreaker_len_arr.min { |old_word, new_word| old_word.length <=> new_word.length } -end -#end - - - - - - - - - - - - - - - - - -# def highest_score_from(words) -# highest_score_hash = { - -# } -# score = 0 -# winning_word = "" -# # tie_breaker_words = [] -# words.each do |object| -# word_score = score_word(object) -# if word_score > score -# score = word_score -# winning_word = object -# # elsif word_score = score -# # word_length = object.chars.length -# # winning_word_length = winning_word.chars.length -# # if word_length < winning_word_length -# # winning_word = object -# # elsif word_length == 10 -# # winning_word = object -# # elsif winning_word_length == 10 -# # winning_word -# # end -# # end - -# # tie_breaker_words>> winning_word -# # tie_breaker_words>> object -# elsif word_score = score -# winning_word = tiebreaker_length(winning_word, object) -# else -# score -# end - -# highest_score_hash[:word] = winning_word -# highest_score_hash[:score] = score - -# return highest_score_hash -# # highest_score_hash[:score => score] -# # end -# # p highest_score_hash -# end - - -# def tiebreaker_length (old_word, new_word) -# tiebreaker_len_arr = [old_word, new_word] -# tiebreaker_len_arr.min { |old_word, new_word| old_word.length <=> new_word.length} - -# end - +end \ No newline at end of file