Skip to content

Instantly share code, notes, and snippets.

  • Select an option

  • Save anonymous/5f820964532cf3dd6469 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/5f820964532cf3dd6469 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/srkama 's solution for Bonfire: Seek and Destroy
// Bonfire: Seek and Destroy
// Author: @srkama
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy?solution=function%20destroyer(arr)%20%7B%0A%20%20%20args%20%3D%20Array.prototype.slice.call(arguments)%3B%0A%20%20%20args.slice(1).forEach(function(e%2Cl%2Ca)%20%7B%0A%20%20%20arr%20%3D%20arr.filter(function(value)%20%7B%0A%20%20%20%20%20%20%20console.log(value%3D%3De)%3B%0A%20%20%20%20%20%20%20return%20(value!%3De)%3B%0A%20%20%20%20%20%7D)%3B%0A%20%20%20%7D)%3B%0A%20%20return%20arr%3B%0A%7D%0A%0Adestroyer(%5B%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%2C%202%2C%203%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function destroyer(arr) {
args = Array.prototype.slice.call(arguments);
args.slice(1).forEach(function(e,l,a) {
arr = arr.filter(function(value) {
console.log(value==e);
return (value!=e);
});
});
return arr;
}
destroyer([[1, 2, 3, 1, 2, 3], 2, 3]);
@srkama
Copy link

srkama commented Nov 30, 2015

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.

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