Skip to content

Instantly share code, notes, and snippets.

@MagnusRufum
MagnusRufum / bubble_sort.rb
Created June 18, 2018 17:04
Bubble Sort Ruby solution for The Odin Project
def bubble_sort(array)
loop do
swapped = false
(array.length-1).times do |i|
if array[i] > array[i+1]
array[i], array[i+1] = array[i+1], array[i]
swapped = true
end
end
break if not swapped