Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created February 8, 2014 20:43
Show Gist options
  • Save trikitrok/907f0989809a7a46adbe to your computer and use it in GitHub Desktop.
Save trikitrok/907f0989809a7a46adbe to your computer and use it in GitHub Desktop.
Conways rules js code
var rules = (function () {
function hasThreeNeighbors(numberOfNeighbors) {
return numberOfNeighbors == 3;
}
function hasTwoNeighbors(numberOfNeighbors) {
return numberOfNeighbors == 2;
}
return {
goesOnLivingWith: function (numberOfNeighbors) {
return hasThreeNeighbors(numberOfNeighbors) ||
hasTwoNeighbors(numberOfNeighbors);
},
isCreatedWith: function (numberOfNeighbors) {
return hasThreeNeighbors(numberOfNeighbors);
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment