Skip to content

Instantly share code, notes, and snippets.

@airicbear
Last active June 25, 2021 22:42
Show Gist options
  • Save airicbear/0a5b920256c58dcedf6452f49a164d15 to your computer and use it in GitHub Desktop.
Save airicbear/0a5b920256c58dcedf6452f49a164d15 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
def bubblesort(array)
array.each_with_index do |_, i|
(0..(array.length - 2 - i)).each_with_index do |_, j|
array[j], array[j + 1] = array[j + 1], array[j] if array[j] > array[j + 1]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment