Delete duplicates of in 2-dimensional arrays
We have an array:
arr = []
And we make it 2-dimensional
arr = [
[1, 2, 3, 4],
[2, 3, 4, 5],
[4, 3, 5, 2],
[2, 3, 4, 5],
[1, 2, 3, 4]
]
Now a question: How to delete duplicated 'lines' from an array?
Line
is second-dimensional array, lets say arr[0]: its contains 'line' => [1, 2, 3, 4], and arr[4] contains [1, 2, 3, 4].
So in result I need to get:
arr = [
[1, 2, 3, 4],
[2, 3, 4, 5],
[4, 3, 5, 2],
]
We can do something like: get arr[0] and check it with arr[1], arr[2], arr[3]...
And then arr[1] with arr[2], arr[3]...
And so on...
But its too slow, so lazy...
Maybe there are some other methods?
I'll try arr.contains(arr[0])
with arr.removeElement(arr[0])
, but some elements get lost :(
Try to create new array arr2 and put in it 'lines' from arr and then deleting them from arr:
arr2 = []
d = []
while arr.length > 0
d = arr[0]
arr2.push(d)
arr.removeElement(d)
end
//arr2 missed some elements
Any suggestions?