power2
v1.0.4
Published
Get what power two numbers has
Downloads
10
Readme
power2
Get what power two numbers has.
Usage
For Node.JS:
var Power2 = require('power2');
For HTML:
<script src="power2.js"></script>
Basic
console.log(Power2(50)); //32, 16, 2
Util example
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;
}