Skip to content

Instantly share code, notes, and snippets.

@astamm78
Last active December 14, 2015 14:48
Show Gist options
  • Save astamm78/5102980 to your computer and use it in GitHub Desktop.
Save astamm78/5102980 to your computer and use it in GitHub Desktop.
A method to sort an array, using a recursive method
def sorter(array)
working = array.clone
self.rec_sort(working, [])
end
def rec_sort(unsorted, sorted)
while unsorted.length > 0
value = unsorted.inject do |first, second|
first < second ? first : second
end
sorted.push(value)
unsorted.delete(value)
unsorted.rec_sort(unsorted, sorted)
end
return sorted
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment