Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MinSomai/b6a7813d686b17cad19b15c146dbb36a to your computer and use it in GitHub Desktop.
Save MinSomai/b6a7813d686b17cad19b15c146dbb36a to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Seek and Destroy
function destroyer(arr, ...rest) {
let newArray = [...arr];
rest.forEach(item=>{
while(newArray.includes(item)){
newArray = deleteIfFound(arr, item);
}
})
return newArray;
}
function deleteIfFound(filterArray, val){
filterArray.forEach((item, index)=>{
if(item == val){
filterArray.splice(index, 1);
}
});
return filterArray;
}
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