Skip to content

Instantly share code, notes, and snippets.

@CliffordAnderson
Last active June 14, 2022 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CliffordAnderson/1f7539afa4956447ef396aa7a3daf1fb to your computer and use it in GitHub Desktop.
Save CliffordAnderson/1f7539afa4956447ef396aa7a3daf1fb to your computer and use it in GitHub Desktop.
Factorial
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