Skip to content

Instantly share code, notes, and snippets.

@morisasy
Last active July 12, 2017 17:13
Show Gist options
  • Save morisasy/e1f964ccf282e4d436f47855c4e5364b to your computer and use it in GitHub Desktop.
Save morisasy/e1f964ccf282e4d436f47855c4e5364b to your computer and use it in GitHub Desktop.
Given an array and a keeper element, create a function "keep" returns an array containing the items that match the given keeper element.
Notes:
* If no elements match, "keep" should return an empty array.
function keep(array, keeper) {
if(Array.isArray(array) === false){
return null;
}
return array.filter(function(value) {
return value == keeper;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment