Options
All
• Public
• Public/Protected
• All

# Class AutoPercentage

A class to help with specific use-cases where you are using a percentage (ex. `1 / n`) but don't know `n` until runtime.

example
``````const autoPercentage = new AutoPercentage();const steps = [    { name: 'init', progress: autoPercentage.percentage() },    { name: 'modify', progress: autoPercentage.percentage() },    { name: 'verify', progress: autoPercentage.percentage() },    { name: 'cleanup', progress: 0 }];let progress = 0;for (const step of steps) {    if (progress === 1) {        return;    }    progress += step.progress;    console.log(`\${step.name} finished - job is \${Math.round(progress * 100)}% complete`);}
``````

### Hierarchy

• AutoPercentage

## Properties

_count: number = 0

## Methods

• count(): { [toPrimitive]: any }
• Increment and get the number of times the percentage has been incremented.

Time complexity: O(1)

Space complexity: O(1)

example
``````const autoPercentage = new AutoPercentage();const a = autoPercentage.count();Number(a); // 1const b = autoPercentage.count();Number(a); // 2Number(b); // 2
``````

#### Returns { [toPrimitive]: any }

The number of times this percentage has been incremented

• ##### [toPrimitive]:function
• [toPrimitive](): number
• #### Returns number

• percentage(): { [toPrimitive]: any }
• Increment and get the percentage.

Time complexity: O(1)

Space complexity: O(1)

example
``````const autoPercentage = new AutoPercentage();const a = autoPercentage.percentage();Number(a); // 1const b = autoPercentage.percentage();Number(a); // 0.5Number(b); // 0.5
``````

#### Returns { [toPrimitive]: any }

The percentage

• ##### [toPrimitive]:function
• [toPrimitive](): number
• #### Returns number

Generated using TypeDoc