Skip to content

Instantly share code, notes, and snippets.

@Hoxtygen
Created April 21, 2017 23:18
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 Hoxtygen/3d188836d14e1b3ab5102a13a26d046c to your computer and use it in GitHub Desktop.
Save Hoxtygen/3d188836d14e1b3ab5102a13a26d046c to your computer and use it in GitHub Desktop.
FCC Intermediate Algorithm Scripting
function diffArray(arr1, arr2) {
//create a placeholder array that will contain the resultant values
var newArray = [];
//iterate through arr1
for (var i = 0; i < arr1.length; i++) {
//if arr2 doesn't contain items in arr1
if (arr2.indexOf(arr1[i]) === -1) {
//save it in newArray
newArray.push(arr1[i]);
}
}
//iterate through arr1
for (var j = 0; j < arr2.length; j++) {
//if arr1 doesn't contain items in arr2
if (arr1.indexOf(arr2[j]) === -1) {
//save it in newArray
newArray.push(arr2[j]);
}
}
console.log(newArray);
}
diffArray([1, "calf", 3, "piglet"], [7, "filly"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment