Get what power two numbers has.
For Node.JS:
var Power2 = require('power2');
For HTML:
<script src="power2.js"></script>
console.log(Power2(50)); //32, 16, 2
var Person = {
Options: {
HAIR: 1
, MOUTH: 2
, EYES: 4
, NOSE: 8
}
, create: function (options) {
options = Power2(options);
var features = [];
if (options.contains(this.Options.HAIR)) {
features.push('HAIR');
}
if (options.contains(this.Options.MOUTH)) {
features.push('MOUTH');
}
if (options.contains(this.Options.EYES)) {
features.push('EYES');
}
if (options.contains(this.Options.NOSE)) {
features.push('NOSE');
}
return features;
}
}
var person = Person.create(Person.Options.HAIR | Person.Options.MOUTH | Person.Options.EYES);
Array.prototype.contains = function (value) {
for (var k in this) {
if (this[k] == value) {
return true;
}
}
return false;
}