Created
July 27, 2015 04:29
-
-
Save alexandrebvd/43c43a839ddb82541a09 to your computer and use it in GitHub Desktop.
17.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
function destroyer(arr) { | |
var args = Array.prototype.slice.apply(arguments).slice(1); | |
for (var i in arr) { | |
for (var j in args) { | |
if (arr[i] === args[j]) { | |
arr.splice(i, 1); | |
} | |
} | |
} | |
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
It fails in case of multiple following entry of same number in array and single entry of that number in args.
Please check the correct below.
for (var j =0; j < arrArray.length; j++)
{
for(var k =0; k < argsArray.length; k++)
{
if(arrArray[j] === argsArray[k])
{
arrArray.splice(j,1);
j--;
}
}
}