Tell us what’s happening:
Can I solve the problem through this solution? If I can then what changes should I made.
Your code so far
function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var result;
var result1;
for(var i=0;i<arr1.length;i++)
{
for(var j=0;j<arr2.length;j++)
{
if(arr1[i]!==arr2[j])
{
// var value=arr1[i];
// console.log(value);
result = arr1[i];
newArr.push(result);
}
else if(arr2[j]!==arr1[i])
{
result1 = arr2[j];
newArr.push(result1);
}
else
{
console.log("Both are equal");
}
}
}
return newArr;
}
diffArray([1, 2, 3, 4, 5],[1, 2, 3, 5]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/diff-two-arrays