I'm attempting to create a JavaScript function that can remove duplicates from an array without using the Set, filter, or reduce functions. I've tried using nested loops to compare elements and splice duplicates out of the array, but I seem to be stuck on how to properly remove them. Here is my current code:
function clearDuplicatesInArray(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++) {
if (arr[i] === arr[j]) {
arr.splice(i, 1);
}
}
}
return arr;
}
clearDuplicatesInArray([1, 1, 2, 3]);