Last active
June 14, 2022 22:59
-
-
Save CliffordAnderson/1f7539afa4956447ef396aa7a3daf1fb to your computer and use it in GitHub Desktop.
Factorial
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
xquery version "3.1"; | |
declare function local:fac($n as xs:int) as xs:int { | |
if ($n = 0) then 1 | |
else if ($n = 1) then 1 | |
else $n * local:fac($n - 1) | |
}; | |
declare function local:hFac($n as xs:int) as xs:int { | |
fn:fold-right(1 to $n, 1, function($a, $b) { $a * $b }) | |
}; | |
local:hFac(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment