Skip to content

Instantly share code, notes, and snippets.

@Hoxtygen
Created December 16, 2016 05:21
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/1976b2471df0ddb88089e569954ef262 to your computer and use it in GitHub Desktop.
Save Hoxtygen/1976b2471df0ddb88089e569954ef262 to your computer and use it in GitHub Desktop.
function destroyer(arr) {
//create a temporary array that includes both the arrays and the arguments, giving a multidimensional array.
var args = Array.prototype.slice.call(arguments);
//cut out the original array by splicing it out leaving only the arguments
args.splice(0,1);
//create an empty array that will contain the result after the array and arguments have been compared
var newArr= [];
//iterate through the original array
for (var i = 0; i < arr.length; i++) {
//iterate through the arguments array
for (var j = 0; j < args.length; j++) {
//if they both have values in common, delete them.
if (arr[i] == args[j]) {
delete arr[i];
}
}
}
/* assign the resulting value to the "newArr" variable created above. However, it needs to be filtered as it contains
empty spaces(null values) left behind by the deleted values. Leaving the null values will corrupt the array and the
challenge will not be passed.
*/
newArr = arr.filter(function(x) {
return x !==undefined && x !==null & x!==false && x === x && x !==0 && x !== "";
});
console.log(newArr);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment