Created
June 21, 2016 14:46
-
-
Save brainyfarm/1a72fb4bace3537c81d62b0abf026b61 to your computer and use it in GitHub Desktop.
Olawale/FreeCodeCamp Algorithm: 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
function destroyer(arr) { | |
// Covert the arguments into a workable array and changeable array. | |
var args = Array.prototype.slice.call(arguments); | |
// Save the first part of the arguments which is our actual array | |
var mainArr = args[0]; | |
// Remove the first part of the argument from the array which it the array in array | |
// This would return the other parts alone in the array since arr.splice mutates the array unlike slice | |
args.splice(0,1); | |
// Now filter the mainArr and return only items not present in the arg array | |
return mainArr.filter(function(item){return args.indexOf(item) === -1;}); | |
} | |
destroyer([1, 2, 3, 4, 5, 6],2, 3, 4, 5); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment