Skip to content

Instantly share code, notes, and snippets.

Created January 5, 2014 12:15
Show Gist options
  • Save anonymous/8267540 to your computer and use it in GitHub Desktop.
Save anonymous/8267540 to your computer and use it in GitHub Desktop.
def sort arr
rec_sort arr, []
end
def rec_sort unsorted, sorted
if unsorted.length <= 0
return sorted
end
smallest = unsorted.pop
still_unsorted = []
unsorted.each do |tested_object|
if tested_object < smallest
still_unsorted.push smallest
smallest = tested_object
else
still_unsorted.push tested_object
end
end
sorted.push smallest
rec_sort still_unsorted, sorted
end
puts(sort(['can', 'feel', 'singing', 'like', 'a', 'can']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment