Skip to content

Instantly share code, notes, and snippets.

@bigmeech
Created February 24, 2016 00:01
Show Gist options
  • Save bigmeech/0470c83d5a9f967cb01a to your computer and use it in GitHub Desktop.
Save bigmeech/0470c83d5a9f967cb01a to your computer and use it in GitHub Desktop.
function DoorsWorld(passes){
this.doors = []
this.passes = passes
for(var i = 0; i < 100;i++){
this.doors.push({
number:++i,
state:'closed'
})
}
}
DoorsWorld.prototype.countOpen = function(){
return this.doors.filter(function(door){
return door.state === 'opened'
});
}
DoorsWorld.prototype.countClosed = function(){
return this.doors.filter(function(door){
return door.state === 'closed'
});
}
DoorsWorld.prototype.runPass = function(){
for(var i = 0; i <= this.passes; i++){
this.doors.forEach(function(door, index){
if(index === i){
door.state = door.state ? 'closed' : 'opened'
}
})
}
return this.doors
}
var dw = new DoorsWorld(5)
dw.runPass()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment