RosettaCodeData/Task/Anonymous-recursion/Jq/anonymous-recursion-2.jq

9 lines
201 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
def fib(n):
if n < 0 then error("negative arguments not allowed")
2024-11-04 20:28:54 -08:00
else [2, 0, 1]
| recurse( if .[0] > n then empty
else [ .[0]+1, .[2], .[1]+.[2] ]
end)
| .[1]
end;