Last active
September 22, 2023 09:35
-
-
Save qnnnnez/c7927ac90ad2a9f4d70b81f963bc9bc9 to your computer and use it in GitHub Desktop.
quicksort implementation in jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partition($p): | |
{ | |
"less": (. | map(select(. < $p))), | |
"equal": (. | map(select(. == $p))), | |
"greater": (. | map(select(. > $p))) | |
}; | |
def qsort: | |
( | |
if (. | length | . <= 1) then . else | |
partition(.[0]) | | |
[ | |
(.less|qsort|.[]), | |
(.equal|.[]), | |
(.greater|qsort|.[]) | |
] | |
end | |
); | |
. | qsort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment