@crapthings/lodash-count-elements
v0.0.3
Published
count the elements in an array and return result as key, value
Downloads
1
Readme
lodash-count-elements
Usage
npm i @crapthings/lodash-count-elements
const countels = require('@crapthings/lodash-count-elements')
const array = ['a', 'b', 'c', 'b', 'c', 'c']
console.log(countels(array))
console.log(countels(array, { order: 'desc' })) //default
console.log(countels(array, { order: 'asc' }))
const countels = require('@crapthings/lodash-count-elements')
const example = ['a', 'b', 'c', 'd', 'a', 'a', 'a', 'b', 'e', 'f', 'c', 'c', 'c', 'a']
const test = countels(example, {
take: 2,
reject: ({ key, value }, k) => {
if (key === 'a') return true
}
})
console.log(test)
[ { key: 'c', value: 4 }, { key: 'b', value: 2 } ]