Back to Lo

It Countvalues

docs/data/it-countvalues.md

1.53.0336 B
Original Source

CountValues counts the number of each element in the collection.

go
collection := func(yield func(string) bool) {
    yield("apple")
    yield("banana")
    yield("apple")
    yield("cherry")
    yield("banana")
    yield("apple")
}

counts := it.CountValues(collection)
// counts contains {"apple": 3, "banana": 2, "cherry": 1}