RosettaCodeData/Task/Factorial/Jq/factorial-3.jq
2017-09-25 22:28:19 +02: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] ;