Created
July 21, 2016 22:00
-
-
Save mberlanda/4270de41a1f8769b7112c83654607ce7 to your computer and use it in GitHub Desktop.
Quicksort Algorithm Ruby Functional
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
# source: https://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Ruby | |
class Array | |
def quick_sort | |
h, *t = self | |
h ? t.partition { |e| e < h }.inject { |l, r| l.quick_sort + [h] + r.quick_sort } : [] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment