My maze generator creates walls for each "cell", resulting in duplicate walls - such as the left wall of one cell being identical to the right wall of the adjacent cell. I have managed to convert the maze data into a different program where it is stored in the format [x, y, type], with type representing 0 for horizontal walls and 1 for vertical walls. However, I now face an issue with removing duplicates from the array (e.g. [[0, 0, 0], [0, 1, 0], [0, 0, 0]...], where elements at index 0 and 2 are the same).
I attempted to create a function called removeDuplicates() that takes an array.
function removeDuplicates(arr) {
tempArr = [];
for(var i = 0; i < arr.length; i ++) {
var found = false;
for(var j = 0; j < tempArr.length; j ++) {
if(tempArr[j].equals(arr[i])) {
found = true;
}
}
if(found === false) {
tempArr.push(arr[i]);
}
}
}
But when I run the code, I encounter an error stating that tempArr[j].equals is not a function. What modification should I make to compare arrays for equality? The == operator also did not provide the desired results.