Describe the bug
The my_factorial example function in Basic Computing 2 returns incorrect answers if the input is 0 or 1
To Reproduce
my_factorial <- function(a = 6){
if (as.integer(a) != a) {
print("Please enter an integer!")
} else {
tmp <- 1
for (i in 2:a){
tmp <- tmp * i
}
print(paste(a, "! = ", tmp, sep = ""))
}
}
Describe the bug The my_factorial example function in Basic Computing 2 returns incorrect answers if the input is 0 or 1
To Reproduce my_factorial <- function(a = 6){ if (as.integer(a) != a) { print("Please enter an integer!") } else { tmp <- 1 for (i in 2:a){ tmp <- tmp * i } print(paste(a, "! = ", tmp, sep = "")) } }
FIX: explicitly code in behavior in edge cases