Last active
January 1, 2016 22:09
-
-
Save jackhooper/8208238 to your computer and use it in GitHub Desktop.
Functional-programming style Quicksort implementation written in Ruby, with no data mutation.
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
# 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