Skip to content

Instantly share code, notes, and snippets.

@joePichardo
Created December 10, 2015 21:38
Show Gist options
  • Save joePichardo/b1ae16194994e0016be4 to your computer and use it in GitHub Desktop.
Save joePichardo/b1ae16194994e0016be4 to your computer and use it in GitHub Desktop.
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
// Bonfire: Seek and Destroy
// Author: @joepichardo
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function destroyer(arr) {
// Remove all the values
//get other values (arguments) that are put into the parameters of destroyer
var removeChars = Array.prototype.slice.call(arguments);
//go through the arguments and find each index
//and remove from the array called array
//return that array
for(var i= 0; i < removeChars.length; i++){
while (arr.indexOf(removeChars[i]) != -1){
arr.splice(arr.indexOf(removeChars[i]), 1);
}
}
return arr;
}
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