Our FREE site is mostly funded by the Amazon ads ⇓below⇓.
Support us by clicking ⇑above⇑ next time you plan to buy a product on Amazon.
return  if empty?
# chose a random pivot value
pivot = delete_at(rand(size))
# partition array into 2 arrays and comparing them to each other and eventually returning
# array with the pivot value sorted
left, right = partition(&pivot.method(:>))
# recursively calling the quicksort method on itself
return *left.quicksort, pivot, *right.quicksort
arr = [34, 2, 1, 5, 3]