Hi,
I had seen but was not able to understand functions like reduce,filter etc, now as i need to use a way to filter out duplicates from an array i am trying to make a vanilla JS function, i seem to be successful for 2 duplicates values in a row like - like here -
[3,3,1,1,5];
but not with 3 in a row like [3,3,3,1,1,1,5];
Here the code returns 3 and 1 twice …
My logic is to compare each value other then itself and splice it out if it matches any other value , kindly guide me here …Thanks
var test = [3,3,3,1,1,1,5];
for(var i = 0; i < test.length;i++){
for(var j = i+1; j < test.length;j++){
if(test[i] === test[j]){
test.splice(i,1);
}
}
}
console.log(test);