Created
February 24, 2016 00:01
-
-
Save bigmeech/0470c83d5a9f967cb01a to your computer and use it in GitHub Desktop.
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 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