[Question]
  [
# Alphabetize Integers
For a given set of numbers, put them in alphabetical order when they are spelled out (i.e. 1: one, 2: two, 90: ninety, 19: nineteen). Your code should work for the range `[-999999, 999999]`. Output must have a delimiter between numbers. A space will work, as will a space and a comma as shown in the examples below. Input can be an array of integers, a string of delimited numbers, or however you see fit. All integers are assumed to be unique.
Numbers are not hyphenated for the purposes of this challenge and spaces are alphabetized before any other characters. Negative numbers are assumed to be expressed by using the word `minus`. For example, `four` would precede `four thousand` and the number `-40` would be sorted using the string `minus forty`. Assume all numbers will be solely comprised of number words and no conjunctions (e.g. use `two thousand forty two` instead of `two thousand and forty two`).
---
## Test Cases
**Single Digit Integers:**
Input:
```
1, 2, 3, 4, 5
```
Output:
```
5, 4, 1, 3, 2
```
**Multiple Digit Integers:**
Input:
```
-1002, 5, 435012, 4, 23, 81, 82
```
Output:
```
81, 82, 5, 4, 435012, -1002, 23
```
**Spaces between words, no hyphens, commas or "and":**
Input:
```
6, 16, 60, 64, 600, 6000, 60000, 60004, 60008, 60204, 60804
```
Output:
```
6, 600, 6000, 16, 60, 64, 60000, 60008, 60804, 60004, 60204
```
Remember, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the fewest bytes wins. No loopholes allowed!
  
[Answer]
## Inform 7, ~~214~~ ~~201~~ 118 bytes
[Inform 7](http://inform7.com/) is an absolutely terrible language for golfing, so I wanted to give it a chance here.
Indentation should use tab (`\t`) characters, but HTML doesn't like those. Conversely, Inform doesn't like spaces for indentation, so you'll have to replace the spaces with tabs if you copy-paste the code from here to test it. Or just copy-paste from the Markdown source instead.
Golfed:
```
To X:
    repeat through Table 1:
        now Q entry is "[R entry in words]";
    sort Table 1 in Q order;
    say "[R in Table 1]".
```
Input should be an Inform table, like so (with `\t` between the columns):
```
Table 1
R (number)  Q (text)
-1002
5
435012
4
23
81
82
```
Output:
> 
> 81, 82, 5, 4, 435012, -1002, 23
> 
> 
> 
This function runs through the table once, adding a textual representation of each number in a new column. Then it sorts the table rows according to the text column; in Inform, strings are sorted lexicographically. Finally, it prints out the original column in the new order. Conveniently, Inform 7's ["crude but sometimes useful"](http://inform7.com/learn/man/WI_16_4.html) format for printing out table columns turns out to be comma separated, exactly as requested.
Ungolfed, with boilerplate showing how to call the function:
```
To print the numbers in alphabetical order:
    repeat through the Table of Sortable Numbers:
        now the name entry is "[the index entry in words]";
    sort the Table of Sortable Numbers in name order;
    say "[the index column in the Table of Sortable Numbers]".
Table of Sortable Numbers
index (number)  name (text)
-1002
5
435012
4
23
81
82
There is a room.
When play begins: print the numbers in alphabetical order.
```
[Answer]
# JavaScript (ES6), ~~189~~ ~~179~~ 186 bytes
```
let f =
a=>a.sort((x,y)=>!x-!y||(X=q(x),Y=q(y),X>Y)-(X<Y),q=n=>n<0?"L"+q(-n):n>999?q(n/1e3)+"Z"+q(n%1e3):n>99?q(n/100)+"K"+q(n%100):n>19?"  cYHFVSCO"[n/10|0]+q(n%10):"0PdaIGTQAMWDbXJEURBN"[n|0])
let g = a => console.log(`[${f(a)}]`)
g([1,2,3,4,5])
g([-1002,5,435012,4,23,81,82])
g([0,1000,1100])
```
```
<input id=I value="1 2 3 4 5"><button onclick="g(I.value.match(/\d+/g)||[])">Run</button>
```
The basic idea is to convert each input number into a short string that's in the correct lexographical position compared to all other number-string pairs. Here's the dictionary used: (Don't run the snippet; it's just used to hide the long list.)
```
A eight
B eighteen
C eighty
D eleven
E fifteen
F fifty
G five
H forty
I four
J fourteen
K hundred
L minus
M nine
N nineteen
O ninety
P one
Q seven
R seventeen
S seventy
T six
U sixteen
V sixty
W ten
X thirteen
Y thirty
Z thousand
a three
b twelve
c twenty
d two
```
This creates a very concise way of mapping each number to its lexographically correct position. That's what the recursive `q` function does:
```
q(-X)        => "L" + q(X)
q(XYYY)      => q(X) + "Z" + q(YYY)
q(XYY)       => q(X) + "K" + q(YY)
q(XY >= 20)` => "  cYHFVSCO"[X] + q(Y)
q(X)         => "0PdaIGTQAMWDbXJEURBN"[X]
```
The `0` at the beginning of the string is to ensure that e.g. 100 (`one hundred`, converted to `PK0`) is sorted before `101` (`one hundred one`, converted to `PKP`). This creates an odd scenario where 0 (`zero`) is sorted to the front of the array, so to get around this, in the sorting function we first sort any zeroes to the right with `!x-!y||(...`.
[Answer]
# Mathematica, 67 bytes
```
SortBy[#,#~IntegerName~"Words"~StringReplace~{","->"","-"->""}&]&
```
Unnamed function taking a list of integers as its argument and returning a list of integers as its value. `#~IntegerName~"Words"` is a built-in that changes an integer to its name in English. `IntegerName` sometimes has commas and hyphens in its output, so the `StringReplace` call gets rid of those. (Sadly the hyphen is actually the 3-byte character, 8208, in UTF-8.) Then `SortBy` sorts the original list alphabetically according to the value of the modified integer name.
A nice coincidence: `IntegerName` uses `negative` instead of `minus` in its output—but no word appearing in the names of any of the allowed numbers is alphabetically between those two words, so no replacement is needed!
(Hat tip to ngenisis for reminding me of `Sortby`.)
[Answer]
# Bash + GNU utils + bsdgames, 52
* 4 bytes saved thanks to @izabera.
```
sed 's/.*/echo `echo &|number`:&/e'|sort|sed s/.*://
```
I/O is newline-delimited lines.
* The first sed expression replaces each numerical number with a shell command that outputs the word form of the number (as given by the [bsdgames `number`](http://wiki.linuxquestions.org/wiki/BSD_games) utility), followed by a `:` then the numerical form of the number.
* This is then `sort`ed.
* Then the second `sed` strips leading characters up to and including the `:`, leaving the numerical form sorted as required.
`number` correctly handles "minus", and its output is close enough to the specificed format that the `sort` works as required. It does output "fourty-four" instead of "fourty four", but this shouldn't matter from the sorting perspective.
The bsdgames package may need installation:
```
sudo apt-get install bsdgames
```
The `sed` and `sort` utilities are almost certainly already in your distro.
[Answer]
# Python + inflect, ~~97~~ ~~91~~ 89 bytes
```
from inflect import*
a={x:engine().number_to_words(x)for x in words}
sorted(a,key=a.get)
```
Used the `inflect` library to transform the `words` array of integers into their phonetic/string representation. Stored into a dictionary of k/v pairs where the keys were the numeric representation and values were the string representation. Returned the list of keys as sorted by values.
EDIT: Saved 5 and 3 bytes, thanks to ETHproductions and Alex.S!
[Answer]
# Mathematica, 30 bytes
The answer below outputs a pure function which will take a list of integers as an input and sort them by their alphabetic name. Just what the doctor ordered ;)
```
SortBy[#~IntegerName~"Words"&]
```
Here is the ungolfed version:
```
SortBy[IntegerName[#, "Words"]&]
```
And here is an example usage:
```
SortBy[#~IntegerName~"Words"&][{0,1,2,3,4,5,6,7,8,9,10}]
```
Which could also be written as
```
SortBy[#~IntegerName~"Words"&]@{0,1,2,3,4,5,6,7,8,9,10}
```
They produce identical outputs - in mathematica, `f[x]` is equivilant to `f@x`.
```
Outputs: {8, 5, 4, 9, 1, 7, 6, 10, 3, 2}
```
There is a much longer answer that another user posted in Mathematica. That answer tries to correct for some small differences between the way mathematica alphebatizes numbers to better conform to the way the OP stated numbers should be alphebatized, however the things they correct for don't affect sorting order, and my answer outputs identically to theirs:
```
MyF = SortBy[#~IntegerName~"Words"&];
TheirF = SortBy[#, #~IntegerName~"Words"~ StringReplace~{"," -> "", "-" -> ""} &] &;
MyF[Range[-999999, 999999]] == TheirF[Range[-999999, 999999]]
(*Outputs True*)
```
[Answer]
# Common Lisp, 113 bytes
No external libraries necessary.
```
(print(mapcar #'cdr(sort(loop for i in x collect(cons(format()"~r"i)i))(lambda(y z)(string-lessp(car y)(car z))))))
```
Output if `x` is `'(1 2 3 4 5)`:
```
(5 4 1 3 2)
```
]