Sort the letters of string in alphabetical order: Difference between revisions
Content added Content deleted
(J) |
|||
Line 535: | Line 535: | ||
{{Out}} |
{{Out}} |
||
<pre>" ?Waaaaaaaaabbcceeeefghhhiiiiijkllllllmnoopppssssttt"</pre> |
<pre>" ?Waaaaaaaaabbcceeeefghhhiiiiijkllllllmnoopppssssttt"</pre> |
||
=={{header|J}}== |
|||
J's builtin is 'grade' and sort is a derived function whose domain includes sequences of characters, so:<lang J> /:~ text0 |
|||
Taehiissstt |
|||
/:~ text1 |
|||
"".TTaaabbccdeeeeeeeeeeeeeefghhhhhiijklllmnnnnooooppqrrrrssssttttttuuuvvwxyyz</lang> |
|||
However, sorting characters is easy to implement using [[wp:Bucket_sort|bucket sort]]:<lang J> {{a.#~<:#/.~a.,y}} text0 |
|||
Taehiissstt |
|||
{{a.#~<:#/.~a.,y}} text1 |
|||
"".TTaaabbccdeeeeeeeeeeeeeefghhhhhiijklllmnnnnooooppqrrrrssssttttttuuuvvwxyyz</lang> |
|||
=={{header|jq}}== |
=={{header|jq}}== |