sort.rb
# iterates over an array up to end index and swaps item positions
# if a passed in block returns a positive number when called with the current and next items
iterates over an array up to end index and swaps item positions
if a passed in block returns a positive number when called with the current and next items
iterates over an array up to end index and swaps item positions if a passed in block returns a positive number when called with the current and next items
def single_pass_with_block(array, end_index)
  swaped = false
  (0...end_index).each do |current_index|
    next_index = current_index + 1
    if yield(array[current_index], array[next_index]).positive?
      array[current_index], array[next_index] = array[next_index], array[current_index]
      swaped = true
    end
  end
  swaped
end
def single_pass_with_block ( array , end_index ) swaped = false ( 0 ... end_index ) . each do | current_index | next_index = current_index + 1 if yield ( array [ current_index ] , array [ next_index ] ) . positive? array [ current_index ] , array [ next_index ] = array [ next_index ] , array [ current_index ] swaped = true end end swaped end
iterates over an array up to end index and swaps item positions
if a passed in block returns a positive number when called with the current and next items
iterates over an array up to end index and swaps item positions if a passed in block returns a positive number when called with the current and next items
array
<not_specific>
end_index
<not_specific>