[Question]
  [
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` or `false`, or `0/1`, or any other distinct `true / 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](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden
* Answer must be a full program or a function, not a snippet or a REPL-entry.
* [code-golf](/questions/tagged/code-golf "show questions tagged '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
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~53~~ ~~44~~ ~~40~~ 39 bytes
```
lambda a:`sorted(a)`[2::5]in(a,a[::-1])
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQaJVQnF9UkpqikaiZEG1kZWUam5mnkaiTGG1lpWsYq/k/Lb9IIVMhMw@ICkpLNDStuBQKijLzShQyddQVdO0U1HXSNDI1/0crOTo5u7i6KekoRUVGAMm8fCBRUpSaCqQKgRgk7QykK1OLlWK5AA "Python 2 – TIO Nexus\"/ZgIyGm9eSaOZk25@MkQogyyNDjXbkesIWVg4CiZP8Wga2DOHAuw1dDuQdtgGOugDsfu1J@VVbfrRRiToGTvRYv0f3fir1/V2PwA \"Python 2 – TIO Nexus")
[Answer]
# [Haskell](https://www.haskell.org/), 33 bytes
```
(%)=scanl1
f s=s==max%s||s==min%s
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/X0NV07Y4OTEvx5ArTaHYttjWNjexQrW4pgbEysxTLf6fYxut5Ojk7OLqpqSjFBUZASTz8oFESVFqKpAqBGKQtDOQrkwtBpIpqakpSrFcuYmZeQq2CrmJBb4KBUWZeSUKKiCOQppCzn8A "Haskell – Try It Online")
*Thanks to Ørjan Johansen for 1 byte with aliasing `scanl1` infix.* 
Haskell is an interesting language to golf sorting-based challenges because it does not have a built-in sort, barring a lengthy `import Data.List`. This encourages finding a way to do the task by hand without explicitly sorting.
The code uses `scanl1`, which folds an operation over the list from left to right, keeping track of the intermediate results. So, `scanl1 max` has the effect of listing the cumulative maxima of the list, i.e. the maxima of progressively longer prefixes. For example, `scanl1 max [3,1,2,5,4] == [3,3,3,5,5]`.
The same with `min` checks whether the list is decreasing. The code checks the two cases and combines them with `||`.
Compare to other expressions:
```
(%)=scanl1;f s=s==max%s||s==min%s
f s=or[s==scanl1 q s|q<-[min,max]]
f s=s==scanl1 max s||s==scanl1 min s
f s=any(\q->scanl1 q s==s)[min,max]
f s=any((==s).(`scanl1`s))[min,max]
f s=elem s$(`scanl1`s)<$>[min,max]
```
[Answer]
# [Perl 6](http://perl6.org/), 25 bytes
```
{[le] .comb or[ge] .comb}
```
### How it works:
* `.comb` splits the input into a sequence of characters.
* `le` and `ge` are the *"less or equal"* and *"greater or equal"* string comparison operators.
* `[ ]` around an infix operator, reduces ("folds") the argument list with that operator. (It's smart enough to return True if the input has only zero or one characters.)
* `or` returns True if the expressions on either side of it is true.
[Answer]
# JavaScript (ES6), 43 bytes
```
([...s],q=s+"")=>q==s.sort()|q==s.reverse()
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
Â)¤{å
```
[Try it online!](https://tio.run/nexus/05ab1e#@3@4SfPQkurDS///ryxOBQA "05AB1E – TIO Nexus")
**Explanation**
```
Â)     # pair the input with it's reverse in a list
  ¤{   # get a copy of the reverse and sort it
    å  # check if the sorted copy is in the list of [input,reverse_input]
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
dZSuz2<
```
[Try it online!](https://tio.run/nexus/matl#@58SFVxaZWTz/7@6o5Ozi6ubOgA "MATL – TIO Nexus") Or [verify all test cases](https://tio.run/nexus/matl#S/ifEhVcWmVk898l5L@6o5Ozi6ubOpd6VGQEkMzLBxIlRampQKoQiEHSzkC6MrUYSKakpqaoAwA).
```
d     % Implicitly input string. Push array of consecutive differences of code points
ZS    % Sign. Transforms each entry into 1, 0 or -1
u     % Unique
z     % Number of nonzeros
2<    % Is it less than 2? Implicit display
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~4~~ 5 bytes
```
Ṣm0ẇ@
```
[Try it online!](https://tio.run/nexus/jelly#@/9w56Jcg4e72h3@H91zuP1R0xpvII78/1/d0cnZxdVNXUdBPSoyAkTl5YPIkqLUVBBdCCJAapxBjMrUYhDl4urqog4A)
Originally was `Ṣm0w` at four bytes.
## Explanation
```
Ṣm0ẇ@  Input: string S
Ṣ      Sort S
 m0    Concatenate sort(S) with reverse(sort(S))
   ẇ@  Sublist exists? Check if S is contained in the previous result
```
[Answer]
## Clojure, 47 bytes
```
#(let[c(map int %)a apply](or(a <= c)(a >= c)))
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 70 bytes
```
o(s,a)char*s;{for(a=0;s[1];s++)a|=s[1]-*s&64|*s-s[1]&32;return a!=96;}
```
I was hoping to find a shorter solution based on a recursive function, but it didn't work out due to the output requirement. So here's an imperative approach. At least, C's operator precedence works nicely for the inner loop statement.
[Try it online!](https://tio.run/nexus/c-gcc#VY7LCsIwEEX3/YoxoiS1ii8EjRV8foPPRWwiFjTVTFyI@u21UURyV3PPzJ2ZPKMYCZYchQmRPw6ZoSJucty0dhxrNSaesavrIVZ73WeIdeeqnTY3yt6MBlGK@z3@ysupTk43qWCIVqZZ4zgKglRbsAotULceQmTwCKDQxRStAyUVHEBFbjWJACMoPmGMB69v8CxSTX8Bt4WS8WQ6my9IMfNn69XSBzrzvTVK@USIfeKTq2/dnamP7gp9IJWTJJ@H8zc "C (gcc) – TIO Nexus")
[Answer]
# R, 48 ~~50~~ ~~61~~ bytes
As an unnamed function
```
function(s)sd(range(sign(diff(utf8ToInt(s)))))<1
```
Thanks to @guiseppe for a few extra bytes.
`charToRaw` takes `s` and splits into a raw vector. This is converted to integers and a `diff` applied. `sign` makes the diffs a single unit. `range` reduces the vector to it's minimum and maximum. Then if the standard deviation `sd` is less than 1 it is TRUE
[Try it online!](https://tio.run/##Pck9DoAgDIbh3YtQRjcHPYC7F@CnJSwloeX8FUPiNz353m50GQ1OWhuDeMnQAxcEqYUhVyIYSsfTbtaZv527EThFUee3qRDTQophISP2pY6Y/2/KXg "R – Try It Online")
[Answer]
# MATL, 8 bytes
```
tPvGSXma
```
[**Try it Online!**](https://tio.run/nexus/matl#@18SUOYeHJGb@P@/uqOTi7OLOgA)
**Explanation**
```
        % Implicitly grab the input as a string
tP      % Create a copy that is reversed
v       % Vertically concatenate these
GS      % Grab the input again and sort it
Xm      % Check if each row of the normal and reversed matrix is equal to the sorted one
a       % Check if either row matched
        % Implicitly display the result
```
[Answer]
## Mathematica, 33 bytes
```
0<=##||##>=0&@@ToCharacterCode@#&
```
Based on [this tip](https://codegolf.stackexchange.com/a/47929/8478). Unfortunately, I have to use `ToCharacterCode` instead of `Characters`, because `<=` and `>=` don't compare strings.
[Answer]
# [PowerShell](https://github.com/PowerShell/PowerShell), 61 bytes
```
param($a)$a-in-join(($b=[char[]]$a)|sort),-join($b|sort -des)
```
[Try it online!](https://tio.run/nexus/powershell#@1@QWJSYq6GSqKmSqJuZp5uVn5mnoaGSZBudnJFYFB0bC5SpKc4vKtHUgcipJIG5CropqcWa////r0wtBgA "PowerShell – TIO Nexus")
Takes input `$a`, then checks whether it's `-in` a two-element array. The array is formed by taking `$a`, casting it as a `char`-array, storing that in `$b` for later, piping it to `sort-object` which sorts lexically. The other element is `$b` sorted in `-des`cending order.
[Answer]
# Bash + coreutils, 59 bytes
```
f()(sed 's/\(.\)/\1\
/g'<<<$s|grep .|sort -c$1)
s=$1
f||f r
```
The input string is passed as an argument.
The output is returned in the exit code (0 for truthy, 1 for falsy, as usual), as allowed by [PPCG I/O methods](http://meta.codegolf.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/5330#5330).
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 5 bytes
I've tried to find a 4 bytes solution without success, so for now here's the most interesting 5 bytes solution I've found:
```
:No₎?
```
[Try it online!](https://tio.run/nexus/brachylog2#@2/ll/@oqc/@/3@l1JTkpEQlAA "Brachylog – TIO Nexus")
`o`, the ordering function, can take a parameter: `0` means ascending order, `1` means descending order. We set that parameter to an unbound variable `N`. Brachylog will try different values for `N` (only `0` or `1` are possible), try to unify the result with the input, and return whether any of those tries succeeded.
[Answer]
# [Perl](https://www.perl.org/), 35 bytes
*Saved 4 bytes thanks to [@Xcali](https://codegolf.stackexchange.com/users/72767/xcali) directly, and 4 more indirectly.*
31 bytes of code + `-pF` flag.
```
@b=reverse@a=sort@F;$_=/@a|@b/x
```
[Try it online!](https://tio.run/##K0gtyjH9/98hybYotSy1qDjVIdG2OL@oxMHNWiXeVt8hscYhSb/iv7WCSryCtq2CwX9HJ2cXVzeuqMgIrrx8rpKi1FSuQi6QoDNXZWoxV0pqasq//IKSzPy84v@6vqZ6BoYG/3VzCtwA "Perl – TIO Nexus")
The code sorts the input, and checks if the inputs matches itself sorted (or in reverse order).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
,Ue@Ṣ
```
**[Try it online!](https://tio.run/nexus/jelly#@68TmurwcOei////lxSlpgIA "Jelly – TIO Nexus")**
# How?
```
,Ue@Ṣ - Main link: string
,     - pair string with
 U    - reverse(string)
    Ṣ - sorted(string)
  e@  - exists in with reversed arguments
```
[Answer]
## Haskell, ~~54~~ 50 bytes
```
t a=or[and(zipWith(<=)`f`tail$a)|f<-[(=<<),(<*>)]]
```
Usage example: `t "defggh"` -> `True`. [Try it online!](https://tio.run/nexus/haskell#BcFBCoAgEADAryziQaN@sPaNDiK4YOpCmcieor/bzBQg9wxPLZmX@8FSDTobcxTiS5P9Mm7eOES7Glx2G8K8iRs46IObgAYBlc5cSlUwfw "Haskell – TIO Nexus").
Maybe using `sort` like may other answers is shorter although it requires `import Data.List`. Here's a different approach:
For every function `f` from `[(=<<),(<*>)]`, calculate `and(zipWith(<=)`f`tail$a)` and require any of the results to be `True`. The functions are
```
((=<<) (zipWith(<=)) tail) a
((<*>) (zipWith(<=)) tail) a
```
which both perform comparisons of neighbor elements of the input list `a` with `<=`, but one with the arguments flipped resulting in a `>=`. `and` checks if all comparisons are `True`. 
[Answer]
# PHP, 66 bytes
```
$a=$s=$r=str_split($argv[1]);sort($s);rsort($r);echo$s==$a|$r==$a;
```
takes input from command line argument. Run with `-r`.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 44 bytes
```
->s{[s,s.reverse].include?s.chars.sort.join}
```
[Try it online!](https://tio.run/nexus/ruby#lYxBCsIwFET3nuKTdf03UNGqZ1BLFiUZ2ookmp8K0nr2yF@4FjfzGHgzZbmWqZFKOOGJJLA8BHcbPTbCrm@TsMSU@RqH8C7d6h990Zjtrt4fjqYiczmfFCFq5gQoH8YyWtfTRHOG5JnuYxbqGi2Wvg@1ui@IwgP@x6qUDw "Ruby – TIO Nexus")
[Answer]
# [Racket](https://racket-lang.org/), 93 bytes
```
(define(f s)(let([t(string->list s)])(or(equal?(sort t char<=?)t)(equal?(sort t char>=?)t))))
```
[Try it online!](https://tio.run/nexus/racket#bYxNDoJADEb3nKIZN@3CGyhEUc/gT1xMoIPEcZCZsvD02JAYg7GL16Rfv7fwNjQQbXVnGbFm1wZGB4nQs@BFMElsQ7PMfZtEz1fCLiL3g/UFpi4KCFQ3G1frgoT@BPkU6HzsIJxkKXFgwElqNttytz8YMOfTURk6hURmXb0hyvBhn@C@PcqymctZn2ayUpsvTsqauf5VTO80vgE "Racket – TIO Nexus")
Ungolfed:
```
(define (lex-sorted? string)
  (let ([char-list (string->list string)])
    (or
     (equal? (sort char-list char<=?) char-list)
     (equal? (sort char-list char>=?) char-list))))
```
Using the sort then compare to original approach
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 19 bytes
```
{t:!#x;(t~<x)|t~>x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6ousVJUrrDWKKmzqdCsKamzq6jl4tJXCCkqLcmo5EqLVnJ0cnZxdVOKBbEjIqMgjKjICAgjLx9ClxSlpgJZQJ1uiTnFqXCdzhDpytRiCCMlNTVFKRYAT8Yi2w==)
A little bit lengthy. I have considered using inline assignment, but it seems to be on the same length as this one. Returns `0` for false and `1` for true.
Explanations:
```
{t:!#x;(t~<x)|t~>x}  Main function. Takes x as input
 t:                  Assign variable t to
   !                 Range between 0 to
    #x;              Length of x (exclusive)
       (  <x)        Ascended version of x
         ~           Matches (deep equal)
        t            Variable t
             |       Or
                >x   Descended version of x
               ~     Matches
              t      Variable t
```
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 5 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
r,sṠƇ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faMGCpaUlaboWK4p0ih_uXHCsfUlxUnIxVHDBkpKi1FQIGwA)
#### Explanation
```
r,sṠƇ  # Implicit input
r,     # Pair the input with its reverse
  sṠ   # Sort the input
    Ƈ  # Is this in the list?
       # Implicit output
```
[Answer]
# [J-uby](https://github.com/cyoce/J-uby), 28 bytes
```
(:>>+(A|:==%:sort)&:any?)%:~
```
This is equivalent to the below Ruby code, with `A` equivalent to `chars` and `:~` equivalent to `reverse`:
```
->s{[s,s.reverse].any?{_1.chars==_1.chars.sort}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700K740qXLBIjfbpaUlaboWezSs7Oy0NRxrrGxtVa2K84tKNNWsEvMq7TVVreogSm6qFSi4RSs5Ojm7uCrFcoE5rs4uTo4wTkVlVVWlUixE9YIFEBoA)
[Answer]
# [Arturo](https://arturo-lang.io), 39 bytes
```
$->s[some?@[reverse<=split s]=>sorted?]
```
[Try it!](http://arturo-lang.io/playground?MUX9rS)
```
$->s[                      ; a function taking an argument s
    some?@[...]=>sorted?   ; is at least one item in the list [...] sorted?
    split s                ; convert s from string to block of length-1 strings
    <=                     ; duplicate
    reverse                ; reverse; both stack items get trapped in the list
]                          ; end function
```
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata) + `-e`, 4 bytes
```
oᶜ↔=
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFNtJJurpKOgpJuqlLsgqWlJWm6FivyH26b86htiu2S4qTkYqjggpvGSo5Ozi6ubkpcSlGREUAyLx9IlBSlpgKpQiAGSTsD6crUYiCZkpqaogTRCwA)
```
o       Sort
 ᶜ↔     Optionally reverse
   =    Check equality
```
[Answer]
# MATLAB / Octave, 38 bytes
```
@(x)any(all([x;flip(x)]'==sort(x)',1))
```
[Online demo](http://ideone.com/613pjC)
[Answer]
# JavaScript (ES6) ~~74~~ ~~62~~ ~~50~~ ~~47~~ 43 bytes
```
([...a],b=a+'')=>b==a.sort()|b==a.reverse()
```
After some golfing and bugfixing, this answer ended up being pretty much the same as ETHProduction's, so please check his answer out and give it a `+1`.
[Answer]
# [Pushy](https://github.com/FTcode/Pushy), 7 bytes
```
ogoGo|#
```
[**Try it online!**](https://tio.run/nexus/pushy#@5@fnu@eX6P8//9/pZKi1FQlAA)
Explanation:
```
      \ Implicit: Input on stack as charcodes
og    \ Check if the stack is sorted ascendingly (Push 0/1)
oG    \ Check if the stack is sorted descendingly (Push 0/1)
      \   - Note that this will work regardless of the first check, as input
      \     is guaranteed to be /[A-Za-z]+/
o|    \ Bitwise OR
#     \ Print the result
```
[Answer]
# Pyth, 5 bytes
```
}Q_BS
```
A program that takes input of a `"quoted string"` and prints `True` or `False` as appropriate.
[Test suite](http://pyth.herokuapp.com/?code=%7DQ_BS&test_suite=1&test_suite_input=%22ABCDEF%22%0A%22ZYX%22%0A%22no%22%0A%22tree%22%0A%22q%22%0A%22ABCDC%22%0A%22yes%22%0A%22deed%22&debug=0)
**How it works**
```
}Q_BS   Program. Input: Q
}Q_BSQ  Implicit variable fill
 Q      Is Q
}       in
    SQ  Q sorted
   B    or
  _     Q sorted reversed?
        Implicitly print
```
]