Skip to content

Instantly share code, notes, and snippets.

View noloman's full-sized avatar
🏠
Working from home

Manuel Lorenzo noloman

🏠
Working from home
View GitHub Profile
def bubble_sort(array)
sorted = false
until sorted
puts "Original array: #{array}"
sorted = true
0.upto(array.length - 2) do |i|
res = block_given? ? yield(array[i], array[i + 1]) : array[i] - array[i + 1]
if res > 0
sorted = false
array[i], array[i + 1] = array[i + 1], array[i]