0.1.3 • Published 5 months ago

@fightingdreamer/iter-count v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

iter-count

Description

Count items in Iterable.

Second implementation will count unique items and group them (similar to uniq -c).

Install

bun add @fightingdreamer/iter-count

Usage

import {count} from '@fightingdreamer/iter-count'

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = count(value)
const expect = 3
console.assert(result == expect)
import {countUnique} from '@fightingdreamer/iter-count'

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = countUnique(value)
const expect = new Map([['a', 2], ['b', 1]])
for (const [key, value] of expect.entries()) {
  console.assert(result.get(key) == value)
}

Usage (node / commonjs)

const {count} = require('@fightingdreamer/iter-count')

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = count(value)
const expect = 3
assert(result == expect)
const {countUnique} = require('@fightingdreamer/iter-count')

const value = ['a', 'a', 'b'][Symbol.iterator]()
const result = countUnique(value)
const expect = new Map([['a', 2], ['b', 1]])
for (const [key, value] of expect.entries()) {
  assert(result.get(key) == value)
}

Functions

function count<T>(iterator: Iterable<T>): number

Will count items in 'iterator'.

function countUnique<T>(iterator: Iterable<T>): Map<T, number>

Will count items in 'iterator' and group them into Map.

0.1.2

5 months ago

0.1.1

5 months ago

0.1.3

5 months ago

0.1.0

5 months ago