Last active
December 20, 2015 01:09
-
-
Save MrBean83/6046772 to your computer and use it in GitHub Desktop.
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
def get_grade(grade) | |
average = grade.to_i | |
case average | |
when 90..100 | |
"A" | |
when 80...90 | |
"B" | |
when 70...80 | |
"C" | |
when 60...70 | |
"D" | |
else | |
"F" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def get_grade(array)
// this is how to do it with the inject method
average = array.inject(0) { |sum, num| sum += num }.to_f / array.length
case average
when 90..100
puts"A"
when 80...90
puts"B"
when 70...80
puts"C"
when 60...70
puts"D"
when 0...60
puts"F"
else
puts"Error"
end
end