Skip to content

Instantly share code, notes, and snippets.

@morisasy
Created July 12, 2017 13:42
Show Gist options
  • Save morisasy/df56fcd7a3cecbf599765409bc205d26 to your computer and use it in GitHub Desktop.
Save morisasy/df56fcd7a3cecbf599765409bc205d26 to your computer and use it in GitHub Desktop.
Write a function called "removeElement". Given an array of elements, and a "discarder" parameter, "removeElement" returns an array containing the items in the given array that do not match the "discarder" parameter. Notes: * If all the elements match, it should return an empty array. * If an empty array is passed in, it should return an empty ar…
.
Given an array of elements, and a "discarder" parameter, "removeElement" returns an array containing the items in the given array that do not match the "discarder" parameter.
Notes:
* If all the elements match, it should return an empty array.
* If an empty array is passed in, it should return an empty array.
function removeElement(array, discarder) {
// your code here
if (typeof array === "undefined" && array === null) {
return array;
}
return array.filter(function(value) {
return value !== discarder;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment