Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabrieljmj/power2
Get what power two numbers has
https://github.com/gabrieljmj/power2
Last synced: about 2 months ago
JSON representation
Get what power two numbers has
- Host: GitHub
- URL: https://github.com/gabrieljmj/power2
- Owner: gabrieljmj
- License: other
- Created: 2015-07-01T19:42:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-21T00:02:32.000Z (over 9 years ago)
- Last Synced: 2024-11-19T00:48:25.849Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/power2
- Size: 125 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
power2
=======
Get what power two numbers has.## Usage
For Node.JS:
```js
var Power2 = require('power2');
```
For HTML:
```html```
### Basic
```js
console.log(Power2(50)); //32, 16, 2
```### Util example
```js
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;
}
```