Skip to content

Instantly share code, notes, and snippets.

@olavfosse
Created November 17, 2019 12:46
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 olavfosse/c2b187e38eae47d4ff9f92d3dd7147ce to your computer and use it in GitHub Desktop.
Save olavfosse/c2b187e38eae47d4ff9f92d3dd7147ce to your computer and use it in GitHub Desktop.
const removeFromArray = function (){ // Takes an array and an arbitrary amount of primitive values. Returns an array where all elements from the array which are equal to one of the primitive value are removed.
arguments = Array.prototype.slice.call(arguments);
let array = arguments[0];
let valuesToRemove = arguments.slice(1);
let newArray = [];
array.forEach(element => {
if(!(valuesToRemove.includes(element))) {
newArray.push(element);
}
});
return newArray;
}
module.exports = removeFromArray;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment