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%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.fil
Created
November 17, 2015 08:58
-
-
Save ElliotFriend/2f9db70c2059da0dcc92 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/elliotfriend 's solution for Bonfire: Seek and Destroy
This file contains 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: @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