Skip to content

Instantly share code, notes, and snippets.

@dylanerichards
Created February 11, 2015 21:02
Show Gist options
  • Select an option

  • Save dylanerichards/90e3b0a7400950203ee3 to your computer and use it in GitHub Desktop.

Select an option

Save dylanerichards/90e3b0a7400950203ee3 to your computer and use it in GitHub Desktop.
Sort array descending with max in middle
def sort_descending(array)
halves = array.each_slice((array.length) / 2).to_a
first = halves[0].sort
second = halves[1].sort.reverse
first + second
end
array = [1, 2, 5, 4, 3, 6]
sort_descending(array)
p sort_descending(array) == [1, 2, 5, 6, 4, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment