How can I go through an array and still remove elements from it

56 Views Asked by At

How to iterate through an array starting from the last element? (Ruby) Looks similar but removing elements seems to causing lots of problems such it has no effect.
It is RGSS so use really simple code.

ptl=[[0,3],[1,5],[2],[3,14],[4,0],[5,0],[6,15],[7,9],[8,7],[9,11],[10,16],[11,6],[12],[13,9],[14],[15,14]]

    ps=ptl.sample(3)
    
    pt=(ps[0]+ps[1]+ps[2])
    for i in (ptl.length()-1)..0
         if ptl[i]&ps
            if (ptl[i][0]==pt[j])
                ptl[i]=[]
            end
            if ptl[i][1]==pt[j]
                ptl[i]=[]
            end
            
        end
    end
0

There are 0 best solutions below