user
Task

Write a function/program/subroutine/procedure to sort the characters of a string in lexicographical order.

A *character* for this purpose should be whatever is natural for your language.

Show the results here on this page.   White-space may be optionally removed.

The case   (uppercase and lowercase)   of any letters should be preserved.

Write the function even if your language has a built-in function for it.
assistant
### Semi-realistic version

```
sub sort_within_string ( $_ is copy ) {
    constant @lexographic_order = sort *.fc, map &chr, 1..255;

    return join '', gather for @lexographic_order -> $l {
        my $count = s:g/$l//;
        take $l x $count;
        LAST { warn "Original string had non-ASCII chars: {.raku}" if .chars }
    }
}
say trim .&sort_within_string for q:to/END/.lines;
The quick brown fox jumps over the lazy dog, apparently
Now is the time for all good men to come to the aid of their country.
END

```

Output:

```
,aaabcdeeeefghhijkllmnnoooopppqrrrsTttuuvwxyyz
.aaccddeeeeeeffghhhiiiillmmmNnnooooooooorrrstttttttuwy

```

### Following the actual task title / description

Following a strict interpretation of the actual task title and description.

* Sorts letters. Only letters. Into alphabetical order. Regardless of case. **EVERYTHING** else is ignored / pushed to the end of the "sorted" string. Not **ASCII** order. Not **EBCDIC** order. Only **alphabetical** order. If it ain't in the alphabet, it ain't sorted.
* Sorts letters of the string two characters at a time **as a string**. No breaking up the string into a list or array, sorting that then joining back together; or picking characters out of a string to generate a new string. Sorts a string, as a string, in place.

Sorted output is wrapped in double guillemots to make it easier to see where it starts and ends.

```
sub moronic-sort ($string is copy) {
    my $chars = $string.chars;
    loop {
        for ^$chars {
            if ($string.substr($_, 1).fc gt $string.substr($_ + 1, 1).fc and $string.substr($_ + 1, 1) ~~ /<:L>/)
               or $string.substr($_, 1) ~~ /<:!L>/ {
                $string = $string.substr(0, $_) ~ $string.substr($_ , 2).flip ~ $string.substr($_ + 2 min $chars);
            }
        }
        last if $++ >= $chars;
    }
    $string
}

sub wrap ($whatever) { '»»' ~ $whatever ~ '««' }


# Test sort the exact string as specified in the task title.
say "moronic-sort 'string'\n" ~ wrap moronic-sort 'string';


# Other tests demonstrating the extent of the stupidity of this task.
say "\nLonger test sentence\n" ~ 
wrap moronic-sort q[This is a moronic sort. It's only concerned with sorting letters, so everything else is pretty much ignored / pushed to the end. It also doesn't much care about letter case, so there is no upper / lower case differentiation.];


say "\nExtended test string:\n" ~ my $test = (32..126)».chr.pick(*).join;
say wrap moronic-sort $test;

```

Output:

```
moronic-sort 'string'
»»ginrst««

Longer test sentence
»»aaaaaaabccccccccddddddeeeeeeeeeeeeeeeeeeeeeeeeeffggghhhhhhhhiiiIiiiiiIiiiillllllmmmnnnnnnnnnnnnoooooooooooooooopppprrrrrrrrrrrrrrssssssssssssssssTtttttttttttttttttttuuuuuvwwyyy    ,      /   .    . '     ,        /    .   ' ««

Extended test string:
!kjyxAa+,LGh_8?3lXEwW-D]Ku|SY[@VF\.op{=q>MT 1tJ/$nN(Z*%&9^v57")`PCiOHQe'RUb<gs;6}#cfmrzd42B~0I:
»»AabBCcDdEeFfGghHiIjJkKLlMmnNoOpPqQRrSsTtuUVvwWxXyYZz[@\.{=> 1/$(*%&9^57")`'<;6}#42~0:!+,_8?3-]|««
```