-
-
Save gravataLonga/9596779 to your computer and use it in GitHub Desktop.
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
function emptySet(x) { | |
return false; | |
} | |
function insert(elem, set) { | |
return function(x) { | |
if (x === elem) { // insert smarter comparison here if needed | |
return true; | |
} | |
return function() { return contains(x, set); }; | |
}; | |
} | |
function contains(elem, set) { | |
var retVal = set(elem); | |
while(typeof retVal === 'function') { | |
retVal = retVal(elem); | |
} | |
return retVal; | |
} | |
var aList = insert(3, insert(2, insert(1, emptySet))); | |
console.log("FIRST: " + contains(2, aList)); | |
console.log("SECOND: " + contains(4, aList)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment