Compare two 2 arrays for common values and delete common values before concatenating, Facing issue while running the loop with array

Viewed 95

I am trying to compare the 2 arrays for common values, delete the common values and make a single array by concatenating 2 arrays.

Facing issue (out of bounds, array size is 3) while running the loop with array index size reference

//@version=4
study("`array.concat()`")
a = array.new_float(0)
b = array.new_float(0)
array.push(a, 0)
array.push(a, 1)
array.push(a, 2)
array.push(a, 4)

array.push(b, 0)
array.push(b, 1)
array.push(b, 3)
array.push(b, 4)

disjoint(e,f)=>
    c = e
    d = f
    for i=0 to array.size(e)-1
        for j=0 to array.size(f)-1
            if array.get(e,i) == array.get(f,j)
                array.remove(c,i)
                array.remove(d,i)
    array.concat(c , d)

z = disjoint(a,b)


if barstate.islast
    l1 = label.new(bar_index, 0, "AFTER\na: " + tostring(a) + "\nb: " + tostring(b) + "\nZ: " + tostring(z), style = label.style_label_up, size = size.normal)
    label.delete(l1[1]) 
0 Answers
Related