Skip to content

Instantly share code, notes, and snippets.

  • Select an option

  • Save srkama/ae46ed94d7cfbf7f1381 to your computer and use it in GitHub Desktop.

Select an option

Save srkama/ae46ed94d7cfbf7f1381 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]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment