I have an array with arrays inside. I created an algorithm to find duplicated elements in arrays in the array. It works correctly, but when I start scaling up to thousands or tens of thousands of records, then it is not efficient. How can I make this more efficient? How could I approach this problem differently?
# The goal here is to identify which arrays have duplicated items
# even if the elements are in a different order. Secondly, I want
# to keep the array with the lowest "test" score.
let
check = 1
lowestTest = 9999
arrEnd = []
arrStart = []
push!(arrStart, (elements = [1,2], test = 1))
push!(arrStart, (elements = [3,1,2], test = 7)) #duplicate
push!(arrStart, (elements = [1,4,5], test = 3))
push!(arrStart, (elements = [3,2,1], test = 4)) #duplicate
push!(arrStart, (elements = [4,5,6,2], test = 5))
push!(arrStart, (elements = [1,2,3], test = 6)) #duplicate
push!(arrStart, (elements = [2,3,1], test = 2)) #duplicate
push!(arrStart, (elements = [2,1,3], test = 8)) #duplicate
for x in arrStart
lowestTest = x.test
for y in arrStart
if x.elements != y.elements && length(x.elements) == length(y.elements)
check = 1
for xx in x.elements
if in(xx, y.elements)
check *= 1
else
check *= 0
end
end
if check == 1
if x.test > y.test
lowestTest = y.test
end
end
end
end
# if it has the lowest score, then it wins
if x.test == lowestTest
push!(arrEnd,x)
end
end
# check and see if it worked
for x in arrEnd
println(x)
end
end