Last active
June 25, 2021 22:42
-
-
Save airicbear/0a5b920256c58dcedf6452f49a164d15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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