Created
August 7, 2015 03:16
-
-
Save arsho/4ef9e593c4a0fd33531a to your computer and use it in GitHub Desktop.
diff two arrays of freecodecamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function diff(arr1, arr2) { | |
var newArr = []; | |
for(var i=0;i<arr1.length;i++){ | |
var check=1; | |
for(j=0;j<arr2.length;j++){ | |
if(arr1[i]===arr2[j]) | |
check=0; | |
} | |
if(check===1) | |
newArr.push(arr1[i]); | |
} | |
for(var i=0;i<arr2.length;i++){ | |
var check=1; | |
for(j=0;j<arr1.length;j++){ | |
if(arr2[i]===arr1[j]) | |
check=0; | |
} | |
if(check===1) | |
newArr.push(arr2[i]); | |
} | |
return newArr; | |
} | |
print(diff([1, 2, 3, 5], [1, 2, 3, 4, 5])); | |
diff([1, 2, 3, 5], [1, 2, 3, 4, 5]); | |
function print(s){ | |
console.log(s); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment