Created
July 12, 2017 13:42
-
-
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…
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
. | |
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