g | x | w | all
Bytes Lang Time Link
005Vyxal 3250818T084219ZThemooni
375Bespoke250601T152933ZJosiah W
042JavaScript Node.js250606T103930Zl4m2
048AArch64 machine code250606T101458Z鳴神裁四点一号
008Uiua SBCS240103T214926Zchunes
073Tcl180425T110510Zsergiol
113Google Sheets240103T235840Zz..
014K ngn/k240103T190725Zcoltim
115C++ gcc180308T174632ZToby Spe
004Nekomata + e230621T065452Zalephalp
039Arturo230621T030821Zchunes
028Juby230620T190759ZJordan
005Thunno 2230620T182103ZThe Thon
019K ngn/k221015T125717Zoeuf
039Ruby221015T031727ZJordan
002Vyxal221015T020449ZDialFros
049PowerShell190306T045904Zmazzy
003√ å ı ¥ ® Ï Ø ¿170312T222715Zcaird co
013Add++180307T223023ZASCII-on
026Retina180309T030310ZLeo
068C180308T172304ZToby Spe
018Add++180306T200729Zcaird co
009APL Dyalog Unicode180306T223716ZAdá
033Haskell170130T200618Zxnor
020q/kdb+171218T143546Zmkst
019APL NARS171217T222300Zuser5898
070Swift 4170309T174822ZMr. Xcod
093Standard ML MLton171213T211845ZLaikoni
035Perl170130T184443ZDada
nan170130T213419ZMickyT
047Scala170131T013041ZAria Ax
015Alice170415T225946ZMartin E
0398086 machine code170310T114332Zuser5434
005Brachylog170309T225727ZLeo
075Röda170309T184011Zfergusq
037Python 3.5+170309T182739Zshooqie
011CJam170130T183301ZBusiness
084SmileBASIC170216T150242Z12Me21
063PHP 7170216T060545Zuser6395
nanGNU sed170203T150918Zseshouma
093Racket170202T000328ZRodrigo
066Clojure170131T010543ZCarcigen
138C++170201T180451ZSteadybo
044Ruby170131T104746ZFig
070C gcc170131T172825Znwellnho
024Octave170131T115929Zrahnema1
052Scala170130T225519ZMichael
005Pyth170130T192312ZTheBikin
007Pushy170130T183320ZFlipTack
066PHP170130T214903ZTitus
033Mathematica170130T214800ZMartin E
047Clojure170130T210537ZNikoNyrh
005Jelly170130T190536Zmiles
050Haskell170130T191610Znimi
043JavaScript ES6170130T174413ZLuke
005Pyth170130T200053Zuser4854
025Perl 6170130T190946Zsmls
046Haskell170130T193951ZLaikoni
059Bash + coreutils170130T184629ZMitchell
007MATL170130T185509ZLuis Men
005Pyke170130T184751ZBlue
039Python 2170130T175955ZRod
008MATL170130T175532ZSuever
038MATLAB / Octave170130T175110ZSuever
036Retina170130T175206ZMartin E
043JavaScript ES6170130T174514ZETHprodu
nanTIBasic170130T174037ZTimtech
061PowerShell170130T174021ZAdmBorkB
005Jelly170130T174015ZJonathan
00505AB1E170130T173700ZEmigna

Vyxal 3, 5 bytes

⇄⎂/S∨

Vyxal It Online!

⇄⎂/S∨­⁡​‎‏​⁢⁠⁡‌⁢​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌­
# ‎⁡bottom of stack has infinite copies of input
⇄      # ‎⁢reverse first
 ⎂     # ‎⁣to both the top 2:
  /S   # ‎⁤are they invariant by sort?
    ∨  # ‎⁢⁡logical or
💎

Created with the help of Luminespire.

<script type="vyxal3">
⇄⎂/S∨
</script>
<script>
    args=[["ABCEF"],["ZYX"],["no"],["tree"],["q"],["ABCDC"],["yes"],["deed"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>

Bespoke, 375 bytes

with a word,I check if ordered letters occur in it
what criteria clearly prevents a success?if an A-to-B ordering gets reversed
I record a Boolean for it,checking each one is going down/going up
given elements of alphabet,a pairwise-comparing is needed
each time we apply"less than"we check ordering
we consider a sequence unordered if result is changing;else,it is in orde-r

Outputs 0 for true, and 1 for false.

As the input is processed, two stack values are updated - one to keep track of whether the order is increasing, and one to keep track of whether the order is decreasing. Both are initialized to 1 (meaning the word is both increasing and decreasing). Each pair of characters is then compared twice using STACKTOP LT, and the stack values are updated to reflect the results of these comparisons.

The two stack values are then added together, which results in 0 if the input is neither increasing nor decreasing, and a nonzero value otherwise. STACKTOP F is then used to make the truthy result consistent (which has the effect of flipping the condition from what it normally would be).

JavaScript (Node.js), 42 bytes

([l,...x])=>x.some(c=>c!=l&&x-(x=l<(l=c)))

Try it online!

1 extra byte if must match true and false

At least not longer than sort

AArch64 machine code, 48 bytes

$ objdump -dh f.o

f.o:     file format elf64-littleaarch64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00000030  0000000000000000  0000000000000000  00000040  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  0000000000000000  0000000000000000  00000070  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  0000000000000000  0000000000000000  00000070  2**0
                  ALLOC

Disassembly of section .text:

0000000000000000 <f>:
   0:   38401509        ldrb    w9, [x8], #1
   4:   d280002b        mov     x11, #0x1                       // #1
   8:   d280002c        mov     x12, #0x1                       // #1
   c:   14000005        b       20 <f+0x20>
  10:   6b0a013f        cmp     w9, w10
  14:   9a8bc3eb        csel    x11, xzr, x11, gt
  18:   9a8cb3ec        csel    x12, xzr, x12, lt       // lt = tstop
  1c:   2a0a03e9        mov     w9, w10
  20:   3840150a        ldrb    w10, [x8], #1
  24:   35ffff6a        cbnz    w10, 10 <f+0x10>
  28:   aa0c0160        orr     x0, x11, x12
  2c:   d65f03c0        ret

Synopsis

adr x8,.L.string
bl f
// 1-bit value is stored to x0
ret
.data:
.L.string: .asciz "string"

Algorithm

Kinda ported smls's Perl 6 answer. Here is equivalent one:

def f(s: str) -> bool:
    flag1, flag2 = True, True
    for a,b in zip(s[:-1], s[1:]):
        flag1 = False if a>b else flag1
        flag2 = False if a<b else flag2
    return flag1 or flag2

Original source

/// fn (x8: [*:0]const u8) x0: u1
///   x0: 1 for truthy
.globl f

f:
ldrb w9,[x8],1
mov x11,1; mov x12,1
b 2f

1:
cmp w9,w10
csel x11,xzr,x11,gt
csel x12,xzr,x12,lt
mov w9,w10

2:
ldrb w10,[x8],1
cbnz w10,1b

orr x0,x11,x12
ret

How I tested

$ as -o f.o f.s
$ cat main.s
//! Usage: $0 INPUT
//! Exit status shows
.globl _start
_start:
ldr x8,[sp,16]
bl f
mov x8,93
svc 0
$ as -o main.o main.s
$ ld -o main main.o f.o
$ for x in ABCDEF ZYX no tree q ABCDC yes deed; do ./main "$x"; echo "$x: $?"; done
ABCDEF: 1
ZYX: 1
no: 1
tree: 1
q: 1
ABCDC: 0
yes: 0
deed: 0
$

Uiua SBCS, 9 8 bytes

∊⊏⊟⊃⍖⍏..

Try it!

Tcl, 73 bytes

proc L s {expr {[set C [split $s ""]]in[list [lsort $C] [lsort -de $C]]}}

Try it online!

Google Sheets, 113 bytes

It assumes the input string is in A1.

=OR(MAP({1,0},LAMBDA(o,LEN(REDUCE(A1,SORT(CHAR(ROW(65:90)),1,o),LAMBDA(a,c,REGEXREPLACE(a,"(?i)^"&c&"+",))))=0)))

K (ngn/k), 14 bytes

{^(<x;>x)?!#x}

Try it online!

Returns 0 for "truthy" inputs and 1 for "falsy" inputs.

C++ (gcc), 125 124 123 115 bytes

Very boring obvious solution. We use GCC's internal header to save many includes. Conveniently, std::ranges::is_sorted() accepts equal adjacent elements, so we don't need to pass a std::less_equal<>() to it.

#include<bits/stdc++.h>
int f(auto s){using namespace std::ranges;return is_sorted(s)|is_sorted(s|views::reverse);}

Demo program:

#include <cstdio>
#include <string>

int main(int argc, char **argv)
{
    for (int i = 1;  i < argc;  ++i)
        std::printf("  %s -> %d\n", argv[i], f(std::string{argv[i]}));
}

Nekomata + -e, 4 bytes

oᶜ↔=

Attempt This Online!

o       Sort
 ᶜ↔     Optionally reverse
   =    Check equality

Arturo, 39 bytes

$->s[some?@[reverse<=split s]=>sorted?]

Try it!

$->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

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!

Thunno 2, 5 bytes

r,sṠƇ

Attempt This Online!

Explanation

r,sṠƇ  # Implicit input
r,     # Pair the input with its reverse
  sṠ   # Sort the input
    Ƈ  # Is this in the list?
       # Implicit output

K (ngn/k), 19 bytes

{t:!#x;(t~<x)|t~>x}

Try it online!

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

Ruby, 39 bytes

Returns false for ordered and true for unordered.

->s{!(s+$/+s.reverse)[s.chars.sort*""]}

Attempt This Online!

Vyxal, 2 bytes

ÞȮ

Try it Online!

Simple means is ordered?

PowerShell, 49 bytes

param($a)$a-in(0,1|%{-join($a|% t*y|sort -d:$_)})

Try it online!

√ å ı ¥ ® Ï Ø ¿ , 3 bytes

Ißo

This is a stack-based language that uses cp-1252 encoding. Full description at the link in the title.

How it works

I   - Take input and convert to characters
 ß  - Is sorted?
  o - Output

Add++, 13 bytes

L,B#b+dbRB]Ae

Try it online! Based on @caird coinheringaahing's answer.

Explanation

L,            [arg]                   Lambda with no flags
  B#          [sorted(arg)]           Sort every item in stack
    b+        [sorted]                Reduce top item by addition (string join)
      d       [sorted sorted]         Duplicate
       bR     [sorted reversed]       Reverse top item
         B]   [[sorted reversed]]     Clear stack and add stack as single stack item (sorted + reversed)
           A  [[sorted reversed] arg] Add arguent
            e [result]                Top item is found in second top item (Python's "x in y")

Retina, 26 bytes

O`.
V`
$
¶$+¶$+1¶
(.+)¶\1¶

Try it online!

I still haven't seen a Retina program anywhere making use of the history feature, so here it is.

Explanation

O`.

Sort the input

V`

Reverse it

$
¶$+¶$+1¶

Append at the end of the string a newline , followed by the original input to the program $+, another newline, the result of the first stage $+1, and a final newline. What we get is "input sorted descending¶original input¶input sorted ascending¶"

(.+)¶\1¶

Count the pairs of consecutive identical lines. This can be either 0, if the input was unordered, or 1 if the input was ordered.

C, 68 bytes

This assumes the use of a character encoding such as ASCII where the letters are in ascending (or descending) order.

f(char*s){for(int a=3;*s&&a;++s)a&=s[1]<=*s|2*(s[1]>=*s);return!*s;}

We use variable a to store two flags - bit 0 is set if everything we've seen so far is consistent with an ascending sequence, and bit 1 if it's consistent with descending. Before we've seen anything, both are true.

If both these flags become false before the end of string, we exit the loop before s points at the terminating NUL and so return false (0).

If we reach the end of string, then we return true (1).

Test program

#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
    for (int i = 1;  i < argc;  ++i)
        printf("  %s -> %d\n", argv[i], f(argv[i]));
}

Add++, 28 18 bytes

L,2]dbRAº=
L^,bU#

Try it online!

APL (Dyalog Unicode), 9 bytesSBCS

∨/⍬∘⍋⍷⍒,⍋

Try it online!

∨/ Is it anywhere true that (lit. OR-reduction of)

⍬∘⍋ the indices (viz. those that would put the argument into its current order)

 are found in (each position of)

 the indices that would put the argument into descending order

, followed by

 the indices that would put the argument into ascending order?

Haskell, 33 bytes

(%)=scanl1
f s=s==max%s||s==min%s

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]

q/kdb+, 20 bytes

Solution:

{x in(asc;desc)@\:x}

Examples:

q){x in(asc;desc)@\:x}"tree"
1b
q){x in(asc;desc)@\:x}"yes"
0b
q){x in(asc;desc)@\:x}"ABCDEF"
1b

Explanation:

{x in(asc;desc)@\:x} / the solution
{                  } / anonymous lambda function
                   x / implicit input
               @\:   / apply (@) each left (\:) to x
     (asc;desc)      / list of two functions, sort ascending and descending respectively
 x in                / is x in either sorted/unsorted list?

Notes:

Closest equivalent in K4 would be {x in x@(>:;<:)@\:x} for 20 bytes too...

APL NARS 30 19 chars

{(⊂⍵[⍋⍵])∊(⊂⍵),⊂⌽⍵}

{(⍵[⍋⍵]≡⍵[⍳⍴⍵])∨⍵[⍋⍵]≡⍵[⌽⍳⍴⍵]}

Copy the algo of 'Emigna' in APL...Test

  f¨'ABCDEF' 'ZYX' 'tree' 'q'
1 1 1 1 
  f¨'ABCDC' 'yes' 'deed' 
0 0 0 

Swift 4, 70 bytes

var o=Array(readLine()!);var g=o.sorted();print(o==g||o==g.reversed())

Try it online!

Standard ML (MLton), 99 93 bytes

open Char
fun g(x::y::r)c=c(x,y)andalso g(y::r)c|g&c=1=1
(fn$ =>g$op<=orelse g$op>=)o explode

Try it online! The last line is an anonymous function. Example usage: ((fn$ =>g$op<=orelse g$op>=)o explode) "somestring". Returns true or false.

Ungolfed code:

open Char
fun g (x::y::r) c = c(x,y) andalso g (y::r) c
  | g     _     c = true
fun h s = g s op<= orelse g s op>=
val f = h o explode

Perl, 35 bytes

Saved 4 bytes thanks to @Xcali directly, and 4 more indirectly.

31 bytes of code + -pF flag.

@b=reverse@a=sort@F;$_=/@a|@b/x

Try it online!

The code sorts the input, and checks if the inputs matches itself sorted (or in reverse order).

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!

Scala, 47 bytes

def f(x:String)=x==x.sorted|x==x.sorted.reverse

Alice, 15 bytes, non-competing

/o.zz./
@inssR\

Try it online!

Prints nothing (or rather an empty string) as the falsy value and Jabberwocky as the truthy value.

Explanation

/.../
@...\

This is a template for linear string-processing programs that operate entirely in Ordinal mode. However, the code in between is executed in a zig-zag pattern first from left to right and then right to left. Unfolding this part, the actual program we get looks like this:

i.szR.szno

And here is what that does:

i   Read all input as a string.
.s  Duplicate and sort it.
z   "Drop to substring". If the original contains the sorted version (which means
    they're equal) this results in the empty string, otherwise we get the original back.
R   Reverse the string.
.sz Do the same thing again.
    If either the original or the reversed original was sorted, we end up
    with an empty string (falsy), otherwise we get the reverse of the original
    (truthy, because it's non-empty).
n   Logical NOT. Turns non-empty strings into empty (falsy) strings and
    empty strings into "Jabberwocky".
o   Print the result.

8086 machine code, 68 61 48 46 45 39 bytes

00000000  b2 31 be 82 00 ac 9f 88  c3 ac 3c 0d 74 14 38 c3  |.1........<.t.8.|
00000010  74 f5 e3 03 b1 00 9f 77  05 9e 76 ea eb 03 9e 77  |t......w..v....w|
00000020  e5 4a b4 02 cd 21 c3                              |.J...!.|
00000027

Assembled from:

org 0x100
use16
    mov dl, 0x31
    mov si, 0x82
    lodsb
a:  lahf
b:  mov bl, al
    lodsb
    cmp al, 0x0d
    je y
    cmp bl, al
    je b
    jcxz @f
    mov cl, 0
    lahf
@@: ja @f
    sahf
    jbe a
    jmp n
@@: sahf
    ja a
n:  dec dx
y:  mov ah, 0x02
    int '!'
    ret

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!

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.

Röda, 75 bytes

f s{x=[split(s,sep="")];[s=[sort(x)]&""or s=[sort(x,cmp={|a,b|[a>b]})]&""]}

Try it online!

Alternative solution:

f s{x=[split(s,sep="")];[s in[[sort(x)]&"",[sort(x,cmp={|a,b|[a>b]})]&""]]}

Try it online!

It is possible that shorter solutions exist, but I couldn't find them now.

Python 3.5+, 37 bytes

lambda a:sorted(a)in([*a],[*a][::-1])

CJam, 12 11 bytes

q_$_W%+\#)g

Try it online!

Explanation

q            Push the input
 _$          Duplicate and sort
   _W%       Duplicate and reverse
      +      Concatenate the sorted and the reversed strings
       \     Bring input to the top
        #    Find the index of the input in the other string; returns -1 if not found
         )   Increment
          g  Signum (coerces to 0 or 1)

SmileBASIC, 91 89 84 bytes

DIM A[1]INPUT S$WHILE LEN(S$)>1PUSH A,ASC(POP(S$))-ASC(POP(S$))WEND?MIN(A)*MAX(A)==0

Makes an array of the differences between consecutive characters (and an extra 0), and checks if either the min or max is 0.

PHP 7, 63 bytes

for($s=$argv[1];$s[++$i]&a;)${$s[$i-1]<=>$s[$i]}=1;echo!$${-1};

GNU sed, 97 + 1(r flag) = 98 bytes

If the letters are ordered, the script returns 1, otherwise 0. In sed there are no data types.

s:$: zyxwvutsrqponmlkjihgfedcba:
s:(.*(.)(.).* ).*\2.*\3.*:\1abcdefghijklmnopqrstuvwxyz:i
//c0
c1

To check if all letters are arranged in ascending order, I do a table lookup of each pair of consecutive letters in a descending alphabet, that is I try to find a counter example. Note that // actually repeats the last regular expression match! (see lines 2 and 3)

Run example: the script can test multiple input words, one per line

me@LCARS:/PPCG$ echo -e "tree\nABCDC" | sed -rf word_ordered.sed
1
0

Racket, 93 bytes

(define(f s)(let([t(string->list s)])(or(equal?(sort t char<=?)t)(equal?(sort t char>=?)t))))

Try it online!

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

Clojure, 69 66 bytes

#(let[s(apply str(sort %))](or(= % s)(= %(apply str(reverse s)))))

-3 by inlining reversed.

My original try ended up being a longer version of the other Clojure answer, so I went the "sorted" route. Checks if the original string is equal to a sorted version of itself, or a reversed sorted string. Amazingly, (apply str (reverse s) ended up being shorter than using the built-in reverse string method.

(defn lex? [s]
  ; (apply str ...) basically just turns a list into a string
  (let [sorted (apply str (sort s))
        reversed (apply str (reverse sorted))]
    (or (= s sorted) (= s reversed))))

C++, 138 bytes

#import<algorithm>
using namespace std;f(string s){string u,t=s;sort(t.begin(),t.end());u=t;reverse(u.begin(),u.end());return s==t||s==u;}

Ruby, 44 bytes

->s{[s,s.reverse].include?s.chars.sort.join}

Try it online!

C (gcc), 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!

Octave, 24 bytes

@(s)issorted(s,'either')

Try It Online!

Scala, 52 bytes

def p(s:String)=List(s,s.reverse).contains(s.sorted)

Pyth, 5 bytes

}Q_BS

A program that takes input of a "quoted string" and prints True or False as appropriate.

Test suite

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

Pushy, 7 bytes

ogoGo|#

Try it online!

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

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.

Mathematica, 33 bytes

0<=##||##>=0&@@ToCharacterCode@#&

Based on this tip. Unfortunately, I have to use ToCharacterCode instead of Characters, because <= and >= don't compare strings.

Clojure, 47 bytes

#(let[c(map int %)a apply](or(a <= c)(a >= c)))

Jelly, 4 5 bytes

Ṣm0ẇ@

Try it online!

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

Haskell, 54 50 bytes

t a=or[and(zipWith(<=)`f`tail$a)|f<-[(=<<),(<*>)]]

Usage example: t "defggh" -> True. Try it online!.

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.

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.

Pyth, 5 bytes

}SQ,_

Explanation:

}SQ,_
}SQ      Check if the sorted input is a member ...
   ,_QQ  ... of [reversed input, input]

Perl 6, 25 bytes

{[le] .comb or[ge] .comb}

How it works:

Haskell, 46 bytes

import Data.List
f s=sort s`elem`[s,reverse s]

Try it online! Usage: f "somestring", returns True or False.

Not as interesting as nimi's approach, but some bytes shorter.

Given a string s, we check whether s sorted is euqal to the original or reversed string.

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.

MATL, 7 bytes

dZSuz2<

Try it online! Or verify all test cases.

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

Pyke, 5 bytes

SD_]{

Try it here!

S     -   sorted(input)
   ]  -  [^, v]
 D    -    ^
  _   -   reverse(^)
    { - input in ^

Python 2, 53 44 40 39 bytes

lambda a:`sorted(a)`[2::5]in(a,a[::-1])

Try it online!

MATL, 8 bytes

tPvGSXma

Try it Online!

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

MATLAB / Octave, 38 bytes

@(x)any(all([x;flip(x)]'==sort(x)',1))

Online demo

Retina, 36 bytes

Byte count assumes ISO 8859-1 encoding.

$
¶$_¶$_
O^#`\G.
Or`.\G
(.+)\D*\b\1$

Try it online!

JavaScript (ES6), 43 bytes

([...s],q=s+"")=>q==s.sort()|q==s.reverse()

TI-Basic, 66 + 78 = 144 bytes

Input Str1
For(I,1,length(Str1
inString(Str2,sub(Str1,I,1->L1(I
End
L1->L2
Ans->L3
SortA(L2
SortD(L3
L1=L2 or L1=L3

And in Str2 you must have this (+78 bytes):

`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

PowerShell, 61 bytes

param($a)$a-in-join(($b=[char[]]$a)|sort),-join($b|sort -des)

Try it online!

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 -descending order.

Jelly, 5 bytes

,Ue@Ṣ

Try it online!

How?

,Ue@Ṣ - Main link: string
,     - pair string with
 U    - reverse(string)
    Ṣ - sorted(string)
  e@  - exists in with reversed arguments

05AB1E, 5 bytes

Â)¤{å

Try it online!

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]