Diff Two Arrays

function diffArray(arr1, arr2) {
 let nums=[...arr1,...arr2]
 let arr=[]
 nums.sort()
 let ptr=0;
    while(ptr< nums.length){
        if(nums[ptr]==nums[ptr+1]){
            ptr+=2;
        }
        else {
            arr.push(nums[ptr]);
            ptr+=1;
        }
    }
    console.log(arr)
  return arr;
}

diffArray([1, "calf", 3, "piglet"], [1, "calf", 3, 4]);

Can you describe the problem? Are you getting an error or unexpected results?

Your code is passing for me. I have blurred your code.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.