Jump to content

Sort the letters of string in alphabetical order: Difference between revisions

J
(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}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.