-
-
Save anonymous/059731db026073316761 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/v3rse 's solution for Bonfire: Seek and Destroy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bonfire: Seek and Destroy | |
// Author: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy?solution=var%20currArg%3B%0A%2F%2Fclean%20code%0Afunction%20cleaner(val)%7B%0A%20%20%20%20%20%20return%20val%20!%3D%20currArg%3B%20%2F%2Fafter%20zero%0A%7D%0A%0Afunction%20destroyer(arr)%20%7B%0A%20%20%2F%2F%20Remove%20all%20the%20values%0A%20%20%2F%2Fget%20extra%20arguments%0A%20%20for(var%20i%20%3D%201%3B%20i%3Carguments.length%3B%20i%2B%2B)%7B%0A%20%20%20%20%20console.log(currArg%2B%22%3Abefore%20%22%2Barr)%3B%0A%20%20%20%20currArg%20%3D%20arguments%5Bi%5D%3B%0A%20%20%20%20arr%20%3D%20arr.filter(cleaner)%3B%0A%20%20%20%20console.log(currArg%2B%22%3Aafter%20%22%2Barr)%3B%0A%20%20%7D%0A%20%20return%20arr%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) | |
var currArg; | |
//clean code | |
function cleaner(val){ | |
return val != currArg; //after zero | |
} | |
function destroyer(arr) { | |
// Remove all the values | |
//get extra arguments | |
for(var i = 1; i<arguments.length; i++){ | |
console.log(currArg+":before "+arr); | |
currArg = arguments[i]; | |
arr = arr.filter(cleaner); | |
console.log(currArg+":after "+arr); | |
} | |
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
Monkeyfied a bit. Created a temp array instead of just modifying the old one but filter the old on each iteration. I think I need a break