Forked from anonymous/bonfire-seek-and-destroy?solution=function%20destroyer(arr)%20%7B%0A%20%20%2F%2F%20Remove%20all%20the%20values%0A%20%20var%20result%3B%20var%20args%20%3D%20%5B%5D%3B%0A%0A%20%20for%20(var%20i%20%3D%201%3B%20i%20%3C%20arguments.length%3B%20i%2B%2B)%20
Created
November 11, 2015 04:26
-
-
Save sawant/1d5bc16ad8a279972bd0 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/sawant '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: @sawant | |
// 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%20result%3B%20var%20args%20%3D%20%5B%5D%3B%0A%0A%20%20for%20(var%20i%20%3D%201%3B%20i%20%3C%20arguments.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20args.push(arguments%5Bi%5D)%3B%0A%20%20%7D%0A%0A%20%20result%20%3D%20arr.filter(function(val)%20%7B%0A%20%20%20%20return%20args.indexOf(val)%20%3D%3D%3D%20-1%3B%0A%20%20%7D)%3B%0A%20%20%0A%20%20return%20result%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 result; var args = []; | |
for (var i = 1; i < arguments.length; i++) { | |
args.push(arguments[i]); | |
} | |
result = arr.filter(function(val) { | |
return args.indexOf(val) === -1; | |
}); | |
return result; | |
} | |
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