-
-
Save bsideup/5fda6f0064d8092cab36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fact(num) { | |
return match(num) { | |
when String then fact(num.toInteger()) | |
when(0 | 1) then 1 | |
when 2 then 2 | |
orElse it * fact(it - 1) | |
} | |
} | |
assert fact("5") == 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment