Cracked this pretty easily i mean i started yesterday evening and was done today morning.
I used the consoler to debug using the last test case.
Here is my solution.
function diff(arr1, arr2) { var newArr = []; // Same, same; but different. var newarr2 = []; var newarr1 = []; for(i=0;i<arr2.length;i++) { if(arr1.indexOf(arr2[i])=== -1) { newarr1.push(arr2[i]); } console.log(newarr1); } for(i=0;i<arr1.length;i++){ if(arr2.indexOf(arr1[i])=== -1){ newarr2.push(arr1[i]); } console.log(newarr2); } var newarr = newarr1.concat(newarr2); return newarr; } diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
I used the consoler to debug using the last test case.
[1, "calf", 3, "piglet"], [7, "filly"]
should return [1, "calf", 3, "piglet", 7, "filly"]
.Here is my solution.
function diff(arr1, arr2) { var newArr = []; // Same, same; but different. var newarr2 = []; var newarr1 = []; for(i=0;i<arr2.length;i++) { if(arr1.indexOf(arr2[i])=== -1) { newarr1.push(arr2[i]); } console.log(newarr1); } for(i=0;i<arr1.length;i++){ if(arr2.indexOf(arr1[i])=== -1){ newarr2.push(arr1[i]); } console.log(newarr2); } var newarr = newarr1.concat(newarr2); return newarr; } diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
No comments:
Post a Comment