Given an input string S, return truthy
if all the letters in S are Lexically Ordered: their ASCII values need to be in either ascending or descending order. Return falsy
in other cases.
Input
- Input will be in the same case (all upper- or all lowercase). Your submission should be able to handle both.
- Input will consist of ASCII in the range
[A-Za-z]
only - Input length will be at least 1, up to whatever maximum your language supports.
- Input is a string - not a list of characters, not an array of ASCII-codepoints.
Output
- Output should be
true
orfalse
, or0/1
, or any other distincttrue / false
style output your language can provide. - All true cases need to have the same output, as well as all the false cases. No "False is 0, true is 1, 2, or 3".
Additional rules
- Standard loopholes are forbidden
- Answer must be a full program or a function, not a snippet or a REPL-entry.
- code-golf, shortest answer in bytes wins.
Test cases
Truthy
"ABCDEF"
"ZYX"
"no"
"tree" --> the multiple 'e's don't break the order
"q"
Falsy
"ABCDC"
"yes"
"deed"
Invalid
"Hello" --> invalid input - mixed case-, does not have to be handled
"" --> invalid input - length 0-, does not have to be handled
"\n
" --> invalid input - newline is not in range [A-Za-z]-, does not have to be handled
truthy
orfalsy
. This implies that any values that evaluate totrue
orfalse
are allowed. \$\endgroup\$