Skip to content

Instantly share code, notes, and snippets.

@alexandrebvd
Created July 27, 2015 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandrebvd/43c43a839ddb82541a09 to your computer and use it in GitHub Desktop.
Save alexandrebvd/43c43a839ddb82541a09 to your computer and use it in GitHub Desktop.
17.Bonfire: Seek and Destroy
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);
Copy link

ghost commented Dec 15, 2015

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--;
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment