Skip to content

Instantly share code, notes, and snippets.

@mberlanda
Created July 21, 2016 22:00
Show Gist options
  • Save mberlanda/4270de41a1f8769b7112c83654607ce7 to your computer and use it in GitHub Desktop.
Save mberlanda/4270de41a1f8769b7112c83654607ce7 to your computer and use it in GitHub Desktop.
Quicksort Algorithm Ruby Functional
# 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