inst/extdata/example-number-echo.R

#' ## Exponentiation
#'
#' Exponentiation is built into R:
#' ```{r}
2^4
#' ```
#'
#' Write a function called `expo` that uses a loop to calculate the same result.
#' ```{r, echo=-1}
expo <- function(base, power) {
  result <- 1
  for (i in seq(power)) {
    result <- result * base
  }
  return(result)
}
expo(2, 4)
#' ```
#'
#' @solution Solution
#'
#' ```{r}
expo <- function(base, power) {
  result <- 1
  for (i in seq(power)) {
    result <- result * base
  }
  return(result)
}
#' ```
carpentries/dovetail documentation built on Sept. 23, 2021, 9:35 p.m.