aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0riginaln0 <74508026+0riginaln0@users.noreply.github.com>2024-04-14 07:27:58 +0300
committerLouis Pilfold <louis@lpil.uk>2024-04-15 13:10:48 +0100
commit172143aba44a047c9fc7113670900834ae62cbae (patch)
treeac613108f9f4198d590abe57939984ce9fbab601
parenta1c22e954299de5c823ec47cd2f633355764e3b2 (diff)
downloadtour-172143aba44a047c9fc7113670900834ae62cbae.tar.gz
tour-172143aba44a047c9fc7113670900834ae62cbae.zip
factorial(0) = 1 case added for recursion
Executing a factorial from zero is expected to return one, not "RangeError: Maximum call stack size exceeded"
-rw-r--r--src/content/chapter2_flow_control/lesson05_recursion/code.gleam2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/content/chapter2_flow_control/lesson05_recursion/code.gleam b/src/content/chapter2_flow_control/lesson05_recursion/code.gleam
index ee93a6f..4b24db1 100644
--- a/src/content/chapter2_flow_control/lesson05_recursion/code.gleam
+++ b/src/content/chapter2_flow_control/lesson05_recursion/code.gleam
@@ -9,7 +9,7 @@ pub fn main() {
pub fn factorial(x: Int) -> Int {
case x {
// Base case
- 1 -> 1
+ 0 | 1 -> 1
// Recursive case
_ -> x * factorial(x - 1)