Tell us what’s happening:
I am trying to find a way to filter out duplicate
values from an array.
Your code so far
function diffArray(arr1, arr2) {
const newArr = arr1
.concat(arr2) //joining the two arrays
.sort(function(a, b) {//sorting the array numerically
return a - b;
})
//trying to filter out the duplicate values
.filter(function(item, pos) {
return arr1.indexOf(item) == pos;
})
console.log(newArr);
return newArr;
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Diff Two Arrays
Link to the challenge: