Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/9ddabb749a10ed4c09a0 to your computer and use it in GitHub Desktop.
Save anonymous/9ddabb749a10ed4c09a0 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/elliotfriend 's solution for Bonfire: Seek and Destroy
// Bonfire: Seek and Destroy
// Author: @elliotfriend
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy?solution=function%20destroyer(arr)%20%7B%0A%20%20%2F%2F%20Remove%20all%20the%20values%0A%20%20var%20args%20%3D%20%5B%5D.slice.call(arguments)%3B%20args.shift()%3B%0A%20%20var%20destroyedArray%20%3D%20%5B%5D%3B%0A%20%20arr.filter(function(val)%20%7B%0A%20%20%20%20if%20(args.indexOf(val)%20%3D%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20destroyedArray.push(val)%3B%0A%20%20%20%20%7D%0A%20%20%7D)%3B%0A%0A%20%20return%20destroyedArray%3B%0A%7D%0A%0Adestroyer(%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%2C%202%2C%203)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function destroyer(arr) {
// Remove all the values
var args = [].slice.call(arguments); args.shift();
var destroyedArray = [];
arr.filter(function(val) {
if (args.indexOf(val) === -1) {
destroyedArray.push(val);
}
});
return destroyedArray;
}
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