ruby looping question

Posted by jonepatr on Stack Overflow See other posts from Stack Overflow or by jonepatr
Published on 2011-01-15T06:57:51Z Indexed on 2011/01/15 7:54 UTC
Read the original article Hit count: 148

Filed under:
|
|
|

Hello! I want to make a loop on a variable that can be altered inside of the loop.

first_var.sort.each do |first_id, first_value|
  second_var.sort.each do |second_id, second_value_value|
    difference = first_value - second_value
    if difference >= 0
      second_var.delete(second_id)
    else
      second_var[second_id] += first_value
      if second_var[second_id] == 0
        second_var.delete(second_id)
      end
      first_var.delete(first_id)
    end
  end
end

How do I do this, because this doesn't work?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby