Skip to content

Instantly share code, notes, and snippets.

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 duggiemitchell/d0e37dacc322f540e783 to your computer and use it in GitHub Desktop.
Save duggiemitchell/d0e37dacc322f540e783 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/duggiemitchell 's solution for Bonfire: Seek and Destroy
// Bonfire: Seek and Destroy
// Author: @duggiemitchell
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function destroyer(arr) {
var argCombo = arr.slice.call(arguments);
console.log(argCombo.splice(0,1));
return arr.filter(function(chr) {
return argCombo.indexOf(chr) === -1;
}
);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@duggiemitchell
Copy link
Author

Fist, we must turn the arguments into an array using arr.slice.call(arguments); and assign to the variable argCombo

The splice method modifies the argCombo array and returns the deleted elements as a new array ``console.log(argCombo.splice(0,1)); //output: [1,1]

Now, using the filter() function on arr to remove elements we dont want and return ones we wish to keep. In this case, chr is assigned to elements in array will return chr that are === -1 since filter() returns -1 (or false) for chr that are not present in the array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment