Count the instances of each value in an array, ignoring any non-string values.
Installation
npm install count-array-values --save
Usage
var count = // [// {value: 'bar', count: 3},// {value: 'foo', count: 2},// {value: 'Bar', count: 1},// {value: 'baz', count: 1},// ]
If you'd like to use a more relevant property name than value
, specify it
as the second argument when calling the function:
// [// {fruit: 'apple', count: 2},// {fruit: 'banana', count: 1}// ]
You can also override the name of the count
property:
const packages = 'express' 'lodash' 'express' 'lodash' 'express' 'banana' // [// {package: 'express', dependents: 3},// {package: 'lodash', dependents: 2},// {package: 'banana', dependents: 1}// ]
Tests
npm installnpm test
Dependencies
None
Dev Dependencies
- standard: JavaScript Standard Style
- standard-markdown: Test your Markdown files for Standard JavaScript Style™
- tap-spec: Formatted TAP output like Mocha's spec reporter
- tape: tap-producing test harness for node and browsers
License
MIT