I decided to skip for now the Intermediate Front End projects.
I’ve been slacking off, not doing the exercises. Here’s my diff array
Feedback?
function diffArray(arr1, arr2) {
var newArr = [];
// first, let's combine both arrays, and use this combined array
// so we can iterate through all values of array1 and array2
var compareArray = arr1.concat(arr2);
// iterate through each value in compareArray, using map command
compareArray.map(function(v) {
// for each value, compare against array1. If not found, push to output array
if (arr1.indexOf(v) == -1) {
newArr.push(v);
}
});
// iterate through each value in compareArray, using map command
compareArray.map(function(v) {
// for each value, compare against array2. If not found, push to output array
if (arr2.indexOf(v) == -1) {
newArr.push(v);
}
});
// sort output array. Output array contains numbers that are unique from both array1 and array2.
return newArr.sort();
}
diffArray([1, 2, 3, 5, 13, 12, 11], [0, 1, 2, 3, 4, 5]);