Skip to content

Instantly share code, notes, and snippets.

@mattfield
Created January 27, 2014 10:45
Show Gist options
  • Save mattfield/8646532 to your computer and use it in GitHub Desktop.
Save mattfield/8646532 to your computer and use it in GitHub Desktop.
small, recursive function to detect if item is member of a collection
function car(list){
return list[0];
}
function cdr(list){
return list.slice(1);
}
function memberp(a, list){
if (!list.length) {
return false;
} else if ((car(list) == a) || (memberp(a, cdr(list)))) return true;
}
module.exports = memberp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment