How to add data to array and increase qty for it?

hi . i have a mining that create dimension each time and immediately pushing to an array , i want to increase quantity if data be same
my mining each time create [x,y,qty]

b = []
b.push [10,10,1]
b.push[10,10,1]
b.push[11,4,1]

i want to this result: [ [10,10,2], [11,4,1] ]

I think you’ll have to make b its own class, and implement a method push to do what you want:

e.g.

class MyCollection
  def initialize
    @b = []
  end

  def push item
    # look through @b to see if (x, y) already present, and increment if so
  end
end

I think I would make @b a Hash for (x,y) -> quantity

1 Like