Created
January 31, 2013 02:28
-
-
Save tmcw/4679425 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 join() { | |
var j = {}, stuff = []; | |
j.join = function(newstuff) { | |
var enter = newstuff.filter(function(n) { | |
return stuff.indexOf(n) === -1; | |
}); | |
var gotit = newstuff.filter(function(n) { | |
return stuff.indexOf(n) !== -1; | |
}); | |
var exit = stuff.filter(function(n) { | |
return newstuff.indexOf(n) === -1; | |
}); | |
stuff = newstuff; | |
return { | |
enter: enter, | |
gotit: gotit, | |
exit: exit | |
}; | |
}; | |
return j; | |
} | |
// first: construct a join | |
var myjoin = join(); | |
var j = myjoin.join(['cats']); | |
j.enter; | |
j.gotit; | |
j.exit; | |
// new let's add dogs and kittens | |
var k = myjoin.join(['cats', 'dogs', 'kittens']); | |
k.enter; | |
k.gotit; | |
k.exit; | |
// kittens grow up | |
var l = myjoin.join(['cats', 'dogs']); | |
l.enter; | |
l.gotit; | |
l.exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment