percentage-incrementor

1.0.0 • Public • Published

percentage-incrementor

Store the percentage of an incrementing subset against a total.

Installation

yarn add percentage-incrementor or npm i --save percentage-incrementor

Usage

const PercentageIncrementor = require('percentage-incrementor');
 
// Store the percentage of truthy values incremented.
const truthyPercent = new PercentageIncrementor(val => !!val);
 
// Starts at 0.
truthyPercent.valueOf();
// 0
 
truthyPercent.increment(false).valueOf();
// 0
 
truthyPercent.increment(true).valueOf();
// 0.5
 
truthyPercent.increment(true).valueOf();
// 0.666666666
 
// Use it as a primitive.
if (truthyPercent > 0.5) {
  console.log('yay!');
}
// yay!

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    0

Package Sidebar

Install

npm i percentage-incrementor

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

187 kB

Total Files

13

Last publish

Collaborators

  • chasingmaxwell