RosettaCodeData/Task/Binary-strings/Jq/binary-strings-1.jq

11 lines
308 B
Plaintext

# If the input is a valid representation of a binary string
# then pass it along:
def check_binary:
. as $a
| reduce .[] as $x
($a;
if $x | (type == "number" and . == floor
and 0 <= . and . <= 255) then $a
else error("\(.) is an invalid representation of a byte")
end );