Rearrange a number into alphabetical order 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
&gt;&gt; one, zero, one
&gt;&gt; one, one, zero
Output: 110

Input: 31948
&gt;&gt; three, one, nine, four, eight
&gt;&gt; eight, four, nine, one, three
Output: 84913

Input: 5544
&gt;&gt; five, five, four, four
&gt;&gt; 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 (A057846) found by @DomHastings
Perl 6, &nbsp;32&nbsp; 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 =&gt; 110,
  31948 =&gt; 84913,
  5544 =&gt; 5544,
  1234567890 =&gt; 8549176320,
);

# give the lambda a lexical name for clarity
my &amp;int-sort = {+[~] .comb.sort: *.uniname}

plan 3 * @tests;

for @tests -&gt; $_ ( :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 =&gt; 110
ok 3 - output (110) is an Int

ok 4 - input (31948) is an Int
ok 5 - 31948 =&gt; 84913
ok 6 - output (84913) is an Int

ok 7 - input (5544) is an Int
ok 8 - 5544 =&gt; 5544
ok 9 - output (5544) is an Int

ok 10 - input (1234567890) is an Int
ok 11 - 1234567890 =&gt; 8549176320
ok 12 - output (8549176320) is an Int