npm.io
1.0.0 • Published 8 years ago

add-counter

Licence
MIT
Version
1.0.0
Deps
0
Vulns
0
Weekly
0

add-counter

Adds a counter integer to iterated values.

Installation

Requires Node.js 6.0.0 or above.

npm i add-counter

API

The module exports a single function.

Parameters
  1. iter (iterable): The underlying iterable.
  2. Optional: i (integer): The starting value of the counter. Normally this would be either 0 or 1. Defaults to 0.
Return Value

A generator that, for each iterated value x, yields [i++, x]

Example

const addCounter = require('add-counter')

for (const [i, x] of addCounter(['a', 'b', 'c'])) {
  // [0, 'a']
  // [1, 'b']
  // [2, 'c']
}

Keywords