0
Hey, how you doing? I am trying to develop a javascript function that receives an array of integers, and removes from the array only the repeated terms, I know there are predetermined functions for this, but I am trying to develop more "manual" way, could you help me? I’m having some difficulty.
follows what I tested:
var array_teste = [4, 1, 2, 2, 3, 4, 5, 5, 7, 8, 8, 15];//array de teste para a função
function remove_repetidos(arr) {
for (var i = 0; i < arr.length; i++) {
var teste = arr[i];
console.log(teste);
for (var j = 1; i < arr.length; j++) {
if (arr[j] == teste){
arr.splice(j, 1);
};
};
};
}
console.log(array_teste);
remove_repetidos(array_teste);
console.log(array_teste);
The second
for
hasi < arr.length
when it should bej < arr.length
– Isac
You can use the reduce.
– Lucas Brogni