diff options
author | 0riginaln0 <74508026+0riginaln0@users.noreply.github.com> | 2024-04-14 07:29:24 +0300 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-04-15 13:10:48 +0100 |
commit | e96f969c72a7106993a9e51eb781570520e41404 (patch) | |
tree | e18b330f17fb421e9863180621d7a83990efa2e1 | |
parent | 172143aba44a047c9fc7113670900834ae62cbae (diff) | |
download | tour-e96f969c72a7106993a9e51eb781570520e41404.tar.gz tour-e96f969c72a7106993a9e51eb781570520e41404.zip |
factorial(0) = 1 case added for tail_calls
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/lesson06_tail_calls/code.gleam | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/content/chapter2_flow_control/lesson06_tail_calls/code.gleam b/src/content/chapter2_flow_control/lesson06_tail_calls/code.gleam index f029627..004793b 100644 --- a/src/content/chapter2_flow_control/lesson06_tail_calls/code.gleam +++ b/src/content/chapter2_flow_control/lesson06_tail_calls/code.gleam @@ -12,7 +12,7 @@ pub fn factorial(x: Int) -> Int { fn factorial_loop(x: Int, accumulator: Int) -> Int { case x { - 1 -> accumulator + 0 | 1 -> accumulator // The last thing this function does is call itself // In the previous lesson the last thing it did was multiply two ints |