Sort the letters of string in alphabetical order: Difference between revisions
Sort the letters of string in alphabetical order (view source)
Revision as of 11:25, 17 July 2022
, 1 year agoJ
(J) |
|||
Line 535:
{{Out}}
<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}}==
|