Created
January 27, 2014 10:45
small, recursive function to detect if item is member of a collection
This file contains hidden or 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
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