RosettaCodeData/Task/Factorial/Jq/factorial-3.jq
2023-07-01 13:44:08 -04:00

8 lines
219 B
Text

def fact:
def _fact:
# Input: [accumulator, counter]
if .[1] <= 1 then .
else [.[0] * .[1], .[1] - 1]| _fact
end;
# Extract the accumulated value from the output of _fact:
[1, .] | _fact | .[0] ;