Skip to content

Instantly share code, notes, and snippets.

@jackhooper
Last active January 1, 2016 22:09
Show Gist options
  • Save jackhooper/8208238 to your computer and use it in GitHub Desktop.
Save jackhooper/8208238 to your computer and use it in GitHub Desktop.
Functional-programming style Quicksort implementation written in Ruby, with no data mutation.
# Quicksort in Ruby
# Functional Programming style, with no data mutation.
# Jack Hooper 2014
def quicksort(list)
return list if list.length <= 1
higher, lower = list[1..-1].partition { |i| i > list.first }
quicksort(lower) + [list.first] + quicksort(higher)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment