You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As defined in builtin.jq I find range/3 hard to understand and slow due the double test:
def range($init; $upto; $by):
def _range:
if ($by > 0 and . < $upto) or ($by < 0 and . > $upto)
then ., ((.+$by)|_range)
else . end;
if $by == 0 then $init else $init|_range end
| select(($by > 0 and . < $upto) or ($by < 0 and . > $upto))
;
I suggest this alternative implementation:
def range($init; $upto; $by):
label $out
| ($by>0) as $inc
| ($by<0) as $dec
| $init|recurse(.+$by)
| if $inc and . < $upto or $dec and . > $upto # in range?
then .
else break$out
end
;
In my tests it is 1/3 faster!
The text was updated successfully, but these errors were encountered:
As defined in builtin.jq I find
range/3
hard to understand and slow due the double test:I suggest this alternative implementation:
In my tests it is 1/3 faster!
The text was updated successfully, but these errors were encountered: