Need help to understand what's wrong with my solution

Help me understand what’s wrong with my solution for
function diffArray(arr1, arr2) {
var newArr = [];
var k =[];

for(var i = 0;i<arr1.size;i++){ //looping through arr1
for (var j =0;j<arr2.size;j++){ //looping through arr2
if(arr1[i]!=arr2[j]){ //if the element in arr1 and arr2 are not equal
return newArr.push(arr1[i],arr2[j]); //pushing to the empty newArr
// Same, same; but different.
return newArr;

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);

Thanks in Advance :slight_smile:

Try to solve it using filter and index of or slice. You will see how much easier it is to solve this.

1 Like

Yeah, I thought of that…I was just curious what’s wrong with my logic.

Well … assuming that arr1 and arr2 are indeed arrays … there is no size property on arrays. You need to use the length property.

1 Like

Thank you…I was doing c++ a while ago and was confused with javascript