fork download
  1. def del_list(list)
  2. list.inject({}) { |hash, (id, alfa)|
  3. hash.merge(id => alfa) { |key, self_val, other_val|
  4. if self_val then
  5. self_val
  6. else
  7. if other_val then
  8. other_val
  9. else
  10. nil
  11. end
  12. end
  13. }
  14. }.to_a
  15. end
  16.  
  17.  
  18. LIST = [[1, "a"], [1, nil], [2, "b"], [3, "b"], [4, "b"], [4, nil], [4, nil], [5, nil]]
  19.  
  20. p del_list(LIST)
Success #stdin #stdout 0s 29112KB
stdin
Standard input is empty
stdout
[[1, "a"], [2, "b"], [3, "b"], [4, "b"], [5, nil]]