Created
April 21, 2017 23:18
-
-
Save Hoxtygen/3d188836d14e1b3ab5102a13a26d046c to your computer and use it in GitHub Desktop.
FCC Intermediate Algorithm Scripting
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 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