length of the array for use in
the iterator below.
n = arr.size until n == 0 new_n = 0 (1..n-1).each do |i| if arr[i - 1] > arr[i]
Swap the values of the two elements in question if the previous element is greater than the current element.
arr[i - 1], arr[i] = arr[i], arr[i - 1]
new_n is used to store how along the
array we should go on each pass. This
prevents needless going to the end of
the array when we know those elements
are in the correct order.
new_n = i end end
n to the value of
new_n, collected in the
if statement above. This will continue to get
smaller until it eventially reaches zero.
n = new_n end end