[Question]
  [
Given a non-negative integer (`n`), create a function that returns `n` in alphabetical order, according to the literal spelling of each digit in `n`.
### Examples:
```
Input: 101
>> one, zero, one
>> one, one, zero
Output: 110
Input: 31948
>> three, one, nine, four, eight
>> eight, four, nine, one, three
Output: 84913
Input: 5544
>> five, five, four, four
>> five, five, four, four
Output: 5544
Input: 1234567890
Output: 8549176320
```
Note: the operations in the example are illustrative only and do not need to be included in the output. Only the alphabetically-sorted number needs to be returned.
This is code-golf, so the shortest code in bytes wins.
Edit: the input can be taken in any desired format that best suits your language, and the output can be produced similarly by returning from the function or printing. The input will always be a natural number (including 0) and will not contain leading 0's.
[Relevant OEIS entry](https://oeis.org/A057846) (A057846) found by @DomHastings
  
[Answer]
# [Perl 6](http://perl6.org), ~~32~~ 28 bytes
```
~~{+[~] .comb.sort: \*.Str.uniname}~~
{+[~] .comb.sort: *.uniname}
```
### Explanation:
```
{
  # turn the following into a Numeric
  +
  # fold the following list using string concatenation operator
  [~]
    # split $_ into individual characters
    # (implicit method call on implicit parameter)
    .comb
    .sort:
    *.uniname # sort by the Unicode name of the character (digit)
}
```
### Test:
```
#! /usr/bin/env perl6
use v6.c;
use Test;
my @tests = (
  101 => 110,
  31948 => 84913,
  5544 => 5544,
  1234567890 => 8549176320,
);
# give the lambda a lexical name for clarity
my &int-sort = {+[~] .comb.sort: *.uniname}
plan 3 * @tests;
for @tests -> $_ ( :key($input), :value($expected) ) {
  put '';
  isa-ok $input, Int, "input ($input) is an Int";
  my $output = int-sort $input;
  is $output, $expected, .gist;
  isa-ok $output, Int, "output ($output) is an Int"
}
```
```
1..12
ok 1 - input (101) is an Int
ok 2 - 101 => 110
ok 3 - output (110) is an Int
ok 4 - input (31948) is an Int
ok 5 - 31948 => 84913
ok 6 - output (84913) is an Int
ok 7 - input (5544) is an Int
ok 8 - 5544 => 5544
ok 9 - output (5544) is an Int
ok 10 - input (1234567890) is an Int
ok 11 - 1234567890 => 8549176320
ok 12 - output (8549176320) is an Int
```
[Answer]
## 05AB1E, ~~12~~ ~~11~~ 10 bytes
```
•OWÿ¾•vy†J
```
**Explained**
```
•OWÿ¾•        # push sortorder (236719458)
      v       # for each number in sortorder
       y†     # filter to the front
         J    # join
              # implicitly print
```
[Try it online](http://05ab1e.tryitonline.net/#code=4oCiT1fDv8K-4oCidnnigKBK&input=MzE5NDg)
Saved 1 byte thanks to [Adnan](https://codegolf.stackexchange.com/users/34388/adnan)
[Answer]
# JavaScript (ES6), 54
*Edit* same char count, but avoiding the global variable `z`
Input / output as strings
```
n=>[...n].sort((a,b)=>n[a]-n[b],n='9487216503').join``
```
**Test**
```
f=n=>[...n].sort((a,b)=>n[a]-n[b],n='9487216503').join``
function test() {
  O.textContent=f(I.value)
}
test()
```
```
<input id=I type=number value=31948 oninput='test()'>
<pre id=O></pre>
```
[Answer]
## Haskell, ~~62 51~~ 44 bytes
As @nimi suggested, using a list comprehension is shorter than composing functions:
```
f x=0+read[a|a<-"8549176320",b<-show x,a==b]
```
For reference my version:
```
f n=read.(=<<)(\x->filter(==x)$show n)$"8549176320"
```
The pointfree version is a bit longer:
```
f=flip(read.)"8549176320".(=<<).flip(filter.(==)).show
```
Straightforward: Filter the digits in the correct order and then concatenate the result.
[Answer]
# Pyth, ~~12~~ 10 bytes
```
ox`C" »Ä\0
```
Not sure if it can be golfed further. Input needs to be enclosed in quotes.
2 bytes saved thanks to @isaacg!
In pythonic pseudocode:
```
                Q = input()
o          Q    sort(Q, key = lambda N:
  `C" »Ä\0        repr(base256toDec(" »Ä\0"))
 x        N         .index(N)     # 8 being absent from the number yields -1
                )
```
[Test it here](http://pyth.herokuapp.com/?code=ox%60C%22+%C2%BB%C3%84%5C0&test_suite=1&test_suite_input=%22101%22%0A%2231948%22%0A%225544%22&debug=0).
[Answer]
# Perl, 37 bytes
36 bytes code + 1 byte command line (-F)
```
say sort{8549176320=~/$b.*$a/||-1}@F
```
Usage example:
```
echo -n "04823" | perl -F -M5.010 entry.pl
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 19 bytes
```
Vt'8549176320'&m2$S
```
[**Try it online!**](http://matl.tryitonline.net/#code=VnQnODU0OTE3NjMyMCcmbTIkUw&input=MzE5NDg)
### Explanation
```
V              % Implicitly input number. Convert to string (¹)
t              % Push copy of (¹)
'8549176320'   % Push this string (²), which defines order
&m             % Indices (³) of each element of (¹) in (²)
2$S            % Sort copy of (¹) according to (³). Implicitly display
```
[Answer]
# Jelly, 11 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
“U1°ŀ”OṾf@€
```
[Try it here.](http://jelly.tryitonline.net/#code=4oCcVTHCsMWA4oCdT-G5vmZA4oKs&input=&args=IjMxOTQ4Ig)
## Explanation
```
“U1°ŀ”O       Get the Unicode ordinals of “U1°ŀ”
                (all of which are coincidentally single bytes
                in the Jelly code page!)
              The result is [85, 49, 176, 320].
       Ṿ      Uneval. This gets us the string “85,49,176,320”.
        f@€   For each char in this string, extract all chars
                from the first command line argument that
                equal it.
```
[Answer]
# Mathematica ~~35 78~~ 47 bytes
31 bytes saved thanks to a suggestion by LIAMnYP!
```
FromDigits@SortBy[IntegerDigits@#,IntegerName]&
```
`IntegerDigits` breaks up the number into digits which are then sorted according to their names in English. `FromDigits` assembles the digits into a base-10 number.
---
```
FromDigits@SortBy[IntegerDigits@#,IntegerName]&[1234567890]
```
8549176320
[Answer]
# C, ~~142~~ ~~141~~ 117
Pass parameter as `long long *` to `f()`; the function modifies the parameter:
```
f(long long*n){char*c="8549176320",g[10]={0};for(;*n;*n/=10)++g[*n%10];for(;*c;++c)for(;g[*c-48]--;*n=*n*10+*c-48);}
```
`long long` is necessary since the last test case overflowed an `int` when sorted.
[Answer]
## Python 2 - 95 bytes
```
def s(n):
    l=list("8549176320")
    return "".join(sorted(list(n),key=lambda x: l.index(x)))
```
Attempting further golfing...I think the line 2 is unnecessary and this can become 1 lambda.
EDIT: 49 char version in comments, thx to xnor and vaultah for help.
[Answer]
**-- Oracle 11 (SQL): 164 bytes**
```
  SELECT LISTAGG(DECODE(s,0,'zero',TO_CHAR(TO_DATE(s,'j'),'jsp')),',')WITHIN GROUP(ORDER BY 1)FROM(SELECT SUBSTR(&1,level,1)s FROM dual CONNECT BY LEVEL<=LENGTH(&1));
```
**Long form and explanation**
```
  SELECT LISTAGG(DECODE(s,0,'zero',TO_CHAR(TO_DATE(s,'j'),'jsp')),',') WITHIN GROUP (ORDER BY 1)
  FROM ( SELECT SUBSTR(&1,level,1)s FROM dual
           CONNECT BY LEVEL <= LENGTH(&1)
        );
```
Get the input as parameter to script:
```
  SELECT &1 FROM dual
```
"create" rows by using connect by based on length of input:
```
  CONNECT BY LEVEL <= LENGTH(&1)
```
Rip out each digit from the string for each position:
```
  SELECT SUBSTR(&1,level,1)s FROM dual
```
Convert the digit to Julian date, and back to Char to get spelling:
```
  TO_CHAR(TO_DATE(s,'j'),'jsp')
```
Check for zero - special case.
```
  DECODE(s,0,'zero'
```
Use LISTAGG function to concatenate rows back into a single row list, comma delimited, ordered alphabetically
```
  LISTAGG(DECODE(s,0,'zero',TO_CHAR(TO_DATE(s,'j'),'jsp')),',') WITHIN GROUP (ORDER BY 1)
```
Always fun trying to tweak SQL for things like this ... :) really tests my knowledge of the bugger ... 
[Answer]
# Ruby, 60 bytes
```
->n{n.to_s.chars.sort_by{|c|'8549176320'.index c}.join.to_i}
```
[Answer]
# Racket, ~~142~~ 130 bytes
```
(λ(n)(string->number(list->string(sort(string->list(~a n))char<? #:key(λ(m)(string-ref "9487216503"(-(char->integer m)48)))))))
```
Of which conversions are ~~more than~~ *almost* half of the length (~~76~~ 64 bytes).
[Answer]
# TSQL, 260 bytes
Used reversed bubble sort to avoid refering to the length, to save some bytes
**Golfed:**
```
DECLARE @ varchar(99)=101
,@i INT=99,@j INT=98WHILE @i>1SELECT
@=IIF(CHARINDEX(x,'598327614')>CHARINDEX(y,'598327614'),STUFF(STUFF(@,@j,1,x),@i,1,y),@),@i-=IIF(@j=1,1,0),@j=IIF(@j=1,@i,@j-1)FROM(SELECT
SUBSTRING(@,@i,1)x,SUBSTRING(@,@j,1)y)z
PRINT @
```
**Ungolfed:**
```
DECLARE @s BIGINT=1234567890
DECLARE @ char(99)=@s,@i INT=99,@j INT=98
WHILE @i>1
  SELECT 
    @=IIF(CHARINDEX(x,'236719458')>CHARINDEX(y,'236719458'),
        STUFF(STUFF(@,@j,1,x),@i,1,y),@), 
    @i-=IIF(@j=1,1,0),
    @j=IIF(@j=1,@i,@j-1)
  FROM(SELECT SUBSTRING(@,@i,1)x,SUBSTRING(@,@j,1)y)z
PRINT CAST(@ as bigint)
```
Insisting on using integer types as input and output added 37 bytes
[Answer]
# ClojureScript, 45 bytes
```
#(apply str(sort-by(vec"9487216503")(str %)))
```
Uses some screwy string->int conversion from Javascript leak through, so it's not valid Clojure.
[Answer]
## Firebird, 317 bytes
**Golfed:**
```
select list(s,'')from(with recursive q as(select 1 p,substring(:a from 1 for 1)s from rdb$database q union all select q.p+1 p,substring(:a from q.p+1 for 1)s from q where q.p<char_length(:a))select s from q order by iif(s=8,0,iif(s=5,1,iif(s=4,2,iif(s=9,3,iif(s=1,4,iif(s=7,5,iif(s=3,7,iif(s=2,8,iif(s=0,9,6))))))))))
```
**Ungolfed:**
```
select list(s, '')
from (
   with recursive q as (
      select 1 as p, substring(:a from 1 for 1) s
      from rdb$database q
      union all
      select q.p + 1 as p, substring(:a from q.p + 1 for 1) as s
      from q
      where q.p < char_length(:a)
   )
   select s
   from q
   order by iif(s = 8, 0,
               iif(s = 5, 1,
                  iif(s = 4, 2,
                     iif(s = 9, 3,
                        iif(s = 1, 4,
                           iif(s = 7, 5,
                              iif(s = 3, 7,
                                 iif(s = 2, 8,
                                    iif(s = 0, 9, 6)))))))))
)
```
There's no split functionality in Firebird. Instead I created a recursive query to get the next character over and over. Then reselect those while sorting by our proper order. Finally concatenate those results back together in a list. Override the default comma delimiter with blank. I could save 11 bytes by creating a new dummy table instead of `rdb$database` but I thought that may be against the rules.
[Answer]
## ZX Spectum, machine code, ~~53~~ ~~48~~ ~~47~~ ~~45~~ 44 bytes
```
    org 49200 ; #c030
; table converts ascii to alfabetical order
; start from BASIC with any number as : PRINT "1234567890" AND USR 49208
```
`convtab defb 249 ; zero
 defb 244 ; one
 defb 248 ; two
 defb 247 ; three
 defb 2+205 ; four
 defb 1+205 ; five
 defb 246 ; six
 defb 245 ; seven
 ; defb 0 ; eight
 ; defb 3 ; nine
 ; last 2 conversions hidden in call-command`
```
start Call #2bf1    ; fetch stackindex
    call #2ab2 ; store back
    ld h,#c0    ; set highbyte of table
Sort Push de
loop ld b,d
    ld c,e
    inc de
    ld a,(bc)   ; fetch number
    Ld l,a
    ld a,(de)
    cp 34       ; endmarker "
    Jr z,exit   ; end reached?
    push hl     ; save number
    ld l,a
    Ld a,(hl)   ; convert second number
    pop hl
    cp (hl)     ; compare numbers
    jr nc,loop  ; in order, no swap
swap ld a,(bc)  ; swap original numbers
    ld l,a
    ld a,(de)
    ld (bc),a
    ld a,l
    ld (de),a
Exit pop de
    Ret z
    jr sort     ; check number for order
```
[Answer]
# Factor, 128
```
[ 10 base> [ 48 - ] { } map-as dup [ number>text ] map zip [ second first ] sort-with [ first ] map [ 48 + ] ""map-as 10 >base ]
```
Hooray for builtins! :D
[Answer]
# PHP, 126 bytes
As far as I know php doesn't have any builtins that would really help with this (the best I could do using a usort(str\_split()) was 5 bytes longer) so the only thing I'm happy within this answer is the games played with $i to save a couple of bytes on the itteration.
```
<?php for($i=-1;$i<9;)$a[++$i]=preg_replace("/[^$i]/","",$argv[1]);array_multisort([9,4,8,7,2,1,6,5,0,3],$a);echo implode($a);
```
[Answer]
# APL, 23 bytes
```
{⍎n['8549176320'⍋n←⍕⍵]}
```
Explanation:
* `n←⍕⍵`: get the string representation of `n` and store it in `n`
* `'8549176320'⍋`: find a permutation of `n` that sorts `n` given the order `8549176320`.
* `n[`...`]`: reorder `n` by that permutation
* `⍎`: evaluate the result (to turn it back into a number)
[Answer]
# Clojure, 53 bytes
Well, list comprehension idea from Haskell solution seems to be the shortest:
```
#(apply str(for[p"8549176320"b(str %):when(= p b)]p))
```
My original approach is 1 byte longer:
```
#(apply str(sort-by(zipmap"549176320"(range))(str %)))
```
You can see both function online here: <https://ideone.com/afac5n>
[Answer]
## Common Lisp, 104
```
(lambda(n)(#1=parse-integer(sort(format()"~A"n)'string<= :key(lambda(u)(format()"~R"(#1#(string u)))))))
```
### Ungolfed
```
(lambda (n)
  (parse-integer
   (sort (format nil "~A" n)
         #'string<=
         :key (lambda (u) (format nil "~R" (parse-integer (string u)))))))
```
Convert integer as string, sort characters using the `string<=` comparison while using a custom `:key` function which converts a given character as the English representation of the numerical value it represents. Usually I would not use a key function which does as much as this one, but it costs less in bytes than decorate/sort/undecorate.
[Answer]
# Python 3, 234 bytes
This is a direct translation of [my Factor answer](https://codegolf.stackexchange.com/a/84840/46231), just for fun.
```
def f(n):
 s=list(map(int,str(n)))
 return int("".join(list(map(str,list(map(lambda x:x[1],sorted(list(zip(list(map(lambda t:{0:"zero",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine"}[t],s)),s)))))))))
```
The semantics of the evaluation of "lazy" map and zip objects is the most subtle hard-to-find-bug-inducing piece of genuine horse excrement in the universe. Sometimes, `s = map(f, x)` won't allow `s` to be used properly or at all.
[Answer]
## Pyke, 14 bytes
```
.#uЀB`@
```
[Try it here!](http://pyke.catbus.co.uk/?code=.%23u%04%D0%80%1B%05%EF%86%93B%60%40&input=%221234567890%22)
[Answer]
## C, 80 bytes
Takes a string containing a number in base 10 and prints to `stdio`:
```
F(char*i){for(char*p,d,*o="8549176320";*o;++o)for(p=i;d=*p++;d-*o||putchar(d));}
```
[Answer]
## Python 2.7.11, 67 bytes
```
lambda n:''.join(sorted(list(n),key=lambda s:"9487216503"[int(s)]))
```
Takes a string as input and outputs a string. 
[Answer]
# Python 3, 74 bytes
```
lambda x:''.join(i[1]for i in sorted(['9487216503'[int(j)],j]for j in x))
```
[Answer]
# [PHP](https://php.net/), 107 bytes
```
function($a){usort($a,function($a,$b){return($z=array_flip([8,5,4,9,1,7,6,3,2,0]))[$a]-$z[$b];});return$a;}
```
[Try it online!](https://tio.run/##TY0xa8MwEIV3/YojaLDgCnYdNw5KyFToUGh2VQTFkbEhjYQsD43xb3fPcYfc9N69u@/5xk@7g2888AB7mOr@VsXW3RJuxNB3LkRS@LRFfhZDsLEP5O57E4L5PdXX1ieqxALXuMUMN/iGOb5iqoVQ3OgXflf8rOUo5PLKjRwnyXi0XeyoVzEAlWGKmcZZ5gTZEqxcbPEgrxeTETgnW1DJBku6SynQkrHaBWuqJoF/rulIgYCB3mzVOGh//NVdbPJYI6xgnu@4wqckLOmcHz@Op/evT8lGNv0B "PHP – Try It Online")
Uses a user-defined comparison function to adjust the sorting order.
***Output***
```
101         110
31948       84913
5544        5544
1234567890  8549176320
```
]