aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter2_flow_control/lesson05_recursion/code.gleam
blob: 4b24db18a019e55ca0126aedd84e94771e2f48dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import gleam/io

pub fn main() {
  io.debug(factorial(5))
  io.debug(factorial(7))
}

// A recursive functions that calculates factorial
pub fn factorial(x: Int) -> Int {
  case x {
    // Base case
    0 | 1 -> 1

    // Recursive case
    _ -> x * factorial(x - 1)
  }
}