Skip to content
Snippets Groups Projects
Commit 0984136b authored by Matt Bovel's avatar Matt Bovel
Browse files

Add pre-condition for factorial()

parent 2c19da5f
No related branches found
No related tags found
No related merge requests found
......@@ -6,10 +6,13 @@
import scala.annotation.tailrec
def factorial(n: Int) =
require(n >= 0)
@tailrec
def loop(n: Int, acc: Int): Int =
if n == 0 then acc
else loop(n - 1, acc * n)
loop(n, 1)
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment