Created
March 5, 2016 04:12
-
-
Save marcushat/51c5a7947fe696253fa2 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
var ReasonSwitch = function(reasons) { | |
this.on = !!reasons.length; | |
this.reasons = reasons; //reasons | |
this.bias = 'off'; //implement later, are reasons to stay on or off | |
this.on = function(reason) { | |
var reasons = this.reasons; | |
var switched = false; //default | |
if(!reasons.length) { | |
this.on = false; | |
switched = true; | |
} | |
if(reasons.indexOf(reason) === false) { | |
reasons.push(reason); | |
this.reasons = reasons; | |
} | |
return switched; | |
}; | |
this.off = function(reason) { | |
var reasons = this.reasons; | |
var switched = false; //default | |
if(reasons.indexOf(reason) !== false) { | |
var index = reasons.indexOf(reason); | |
reasons.splice(index, 1); | |
this.reasons = reasons; | |
if(!reasons.length) { | |
this.on = true; | |
switched = true; | |
} | |
} | |
return switched; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment