Tell us what’s happening:
I’m wondering if anyone can help me make this code cleaner. Thanks!
Your code so far
function diffArray(arr1, arr2) {
var newArr = [];
arr2.filter(num => {
if( arr1.indexOf(num) === -1){
newArr.push(num)
}
});
arr1.filter(num => {
if(arr2.indexOf(num) === -1){
if(newArr.indexOf(num) === -1){
newArr.push(num)
}}
});
console.log(newArr)
return newArr;
}
diffArray(["diorite", "andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36
.
Challenge: Diff Two Arrays
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays