Last active
December 15, 2015 08:59
-
-
Save sandbochs/5235442 to your computer and use it in GitHub Desktop.
This file contains 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 valid_triangle?(a, b, c) | |
# If any of the inputs = 0 then lets return false before doing anything else | |
# We don't need: if inputarray[0] > 0 && inputarray[1] > 0 && inputarray[2] > 0 then | |
return false if a == 0 || b == 0 || c == 0 | |
# Let's sort the array before we store it in the new variable | |
# Also, preferred ruby style calls for underscores to separate words | |
#inputarray = [a, b, c] | |
#inputarray.sort! | |
input_array = [a, b, c].sort | |
# Storing the the largest number and sum makes the code more explicit | |
# but I think using the sort makes it clear. | |
#lrgstnumber = inputarray.last | |
#sumfirsttwo = inputarray[0] + inputarray[1] | |
# Returning the result of the conditional is equivalent to this if block | |
#if sumfirsttwo >= lrgstnumber | |
# return true | |
#else | |
# return false | |
#end | |
input_array[0] + input_array[1] > input_array.[2] # or input_array.last, I like consistency | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment