Ordered words: Difference between revisions

Content added Content deleted
m (→‎{{header|jq}}: rm extraneous #)
(→‎{{header|jq}}: simplify and speed-up)
Line 1,757: Line 1,757:
=={{header|jq}}==
=={{header|jq}}==
{{works with|jq|1.4}}
{{works with|jq|1.4}}
<lang jq>def is_sorted:
<lang jq># If your jq already defines until/2, then the following definition can be omitted:
if length <= 1 then true
def until(cond; next):
else .[0] <= .[1] and (.[1:] | is_sorted)
def _until: if cond then . else (next|_until) end;
_until;
end;

# input should be an array
def is_sorted:
if length == 0 then true
else . as $in
| (length - 1) as $lm1
| $lm1 == (0 | until( . == $lm1 or $in[.] > $in[.+1] ; .+1))
end ;


def longest_ordered_words:
def longest_ordered_words: