Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Add error handling to `largest_hypotenuse()` so it ignores incorrect cases and captures largest
# hypotenuse for eligible cases.
source('https://bit.ly/2w2WA9k')
# OR
hypotenuse <- function(side1, side2){
side1 <- as.numeric(side1); side2 <- as.numeric(side2)
sqrt(side1^2 + side2^2)
}
largest_hypotenuse <- function(first, second){
for(i in 1:15){
h <- hypotenuse(first[i], second[i])
if(h > largest_val){
largest_val <<- h
}
}
}
set.seed(100)
first <- sample(10:20, 15, replace = T)
second <- sample(c(10:20, letters), 15, replace = T)
# Call largest_hypotenuse -> errors out
largest_val <- 0
largest_hypotenuse(first, second)
largest_val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.