factorial-spec Pub

Implementation for factorial

End of recursion:

$when:: sample.factorial (n == 0)
   . (payload=1)

Main recursion rule:

$when:: sample.factorial (n > 0)
   sample.factorial (n=(n - 1))
   . (payload=(payload * n))

In pseudocode, it would look like this:

if(n == 0) fact = 1;
else fact = n * fact(n-1)


Was this useful?    

By: Razie | 2019-06-01 .. 2022-06-16 | Tags: spec , dsl , private


Viewed 601 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2024, all rights reserved.