Skip to content

Instantly share code, notes, and snippets.

@tharrington
tharrington / merge_sort.rb
Created December 19, 2013 21:52
Merge sort implementation in Ruby
def merge_sort(a)
return a if a.size <= 1
l, r = split_array(a)
result = combine(merge_sort(l), merge_sort(r))
end
def split_array a
mid = (a.size / 2).round
[a.take(mid), a.drop(mid)]
end