Skip to content

Instantly share code, notes, and snippets.

@arsho
Created August 7, 2015 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arsho/4ef9e593c4a0fd33531a to your computer and use it in GitHub Desktop.
Save arsho/4ef9e593c4a0fd33531a to your computer and use it in GitHub Desktop.
diff two arrays of freecodecamp
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