From e227a9e12c4b1542c23520b4ad3e5d009121fad2 Mon Sep 17 00:00:00 2001 From: matthew lee Date: Wed, 26 Sep 2018 15:37:22 -0400 Subject: [PATCH 1/2] successfully completed --- letsdrill.rb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/letsdrill.rb b/letsdrill.rb index 9371cf5..e586f94 100644 --- a/letsdrill.rb +++ b/letsdrill.rb @@ -1,19 +1,28 @@ def get_letter_grade(integer) - - #Put your code here! - + case integer + when 91..100 + "A" + when 81..90 + "B" + when 71..80 + "C" + when 61..70 + "D" + when integer<60 + "F" + else + "Invalid Input" + end end def shortest_string(array) - - #Put your code here! - + array.sort_by {|string| string.length}[0] end - + ### Don't touch anything below this line ### - + p "Fetch Letter Grade: You should have 2 trues" p get_letter_grade(89) == "B" p get_letter_grade(73) == "C" From 263834011f3e13151d25f584e2d5500162d3139f Mon Sep 17 00:00:00 2001 From: matthew lee Date: Fri, 28 Sep 2018 18:21:17 -0400 Subject: [PATCH 2/2] updated guard and enum method --- letsdrill.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/letsdrill.rb b/letsdrill.rb index e586f94..cfbf059 100644 --- a/letsdrill.rb +++ b/letsdrill.rb @@ -1,4 +1,7 @@ def get_letter_grade(integer) + + return "Invalid Input" unless /\A\d+\z/ =~ integer.to_s + case integer when 91..100 "A" @@ -10,20 +13,19 @@ def get_letter_grade(integer) "D" when integer<60 "F" - else - "Invalid Input" end end def shortest_string(array) - array.sort_by {|string| string.length}[0] + array.min_by {|string| string.length} end ### Don't touch anything below this line ### -p "Fetch Letter Grade: You should have 2 trues" +p "Fetch Letter Grade: You should have 3 trues" +p get_letter_grade("Not an integer") == "Invalid Input" p get_letter_grade(89) == "B" p get_letter_grade(73) == "C" p