Sort the letters of string in alphabetical order: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) |
|||
Line 166: | Line 166: | ||
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre> |
<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
An efficient way to sort an arbitrary JSON string is to use the code points of the constituent characters: |
|||
<lang jq> |
|||
def sort_by_codepoints: |
|||
explode | sort | implode;</lang> |
|||
For example: |
|||
<lang jq>"Is this misspelling of alphabetical as alphabitical a joke ?" |
|||
| sort_by_codepoints</lang>produces<pre>" ?Iaaaaaaaabbcceeefghhhiiiiiijkllllllmnoopppsssssttt"</pre>An alternative definition using `sort` on the characters themselves: |
|||
<lang>def sort_by_characters: |
|||
explode | map([.]|implode) | sort | add;</lang>Are these definitions the same?<lang jq>def dingbats: |
|||
"✁✂✃✄✆✇✈✉✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞✟✠✡✢✣✤✥✦✧✩✪✫✬✭✮✯✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❍❏❐❑❒❖❘❙❚❛❜❝❞❡❢❣❤❥❦❧❶❷❸❹❺❻❼❽❾❿➀➁➂➃➄➅➆➇➈➉➊➋➌➍➎➏➐➑➒➓➔➘➙➚➛➜➝"; |
|||
"Now is the time for all good men to come to the aid of their country.", |
|||
"Is this misspelling of alphabetical as alphabitical a joke ?", |
|||
dingbats |
|||
| (sort_by_codepoints==sort_by_characters) |
|||
</lang>produces<pre>true |
|||
true |
|||
true</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<lang julia>function mergesort!(array) |
<lang julia>function mergesort!(array) |