RosettaCodeData/Task/Integer-comparison/Jq/integer-comparison-1.jq

17 lines
441 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
# compare/0 compares the first two items if they are numbers,
# otherwise an "uncomparable" message is emitted.
def compare:
def english:
if .[0] < .[1] then "less than"
elif .[0] == .[1] then "equal to"
2024-11-04 20:28:54 -08:00
else "greater than" # i.e .[0] > .[1]
2023-07-01 11:58:00 -04:00
end;
if (.[0]|type) == "number" and (.[1]|type) == "number" then
"\(.[0]) is \(english) \(.[1])"
else
"\(.[0]) is uncomparable to \(.[1])"
end ;
compare