1.3.1 • Published 5 years ago

most-common v1.3.1

Weekly downloads
25
License
MIT
Repository
github
Last release
5 years ago

most-common

Donate Travis

Get the n most common elements and their counts from the most common to the least.

Usage

$ npm i --save most-common
const mostCommon = require('most-common');

const words = [
    'javascript',
    'php',
    'node',
    'python',
    'node',
    'mocha',
    'nlp',
    'chai',
    'nlp',
    'most-common',
    'array',
    'string',
    'nlp'
];

console.log(mostCommon(words, 3));
/*
[{
    token: 'nlp',
    count: 3
}, {
    token: 'node',
    count: 2
}, {
    token: 'javascript',
    count: 1
}]
*/

const pangram = 'The quick brown fox jumps over the lazy dog';

console.log(mostCommon(pangram, 3));
/*
[{
    token: ' ',
    count: 8
}, {
    token: 'o',
    count: 4
}, {
    token: 'e',
    count: 3
}]
*/


// Exclude whitespace
console.log(mostCommon(pangram, 3, { excludeWhitespace: true }));
/*
[{
    token: 'o',
    count: 4
}, {
    token: 'e',
    count: 3
}, {
    token: 'u',
    count: 2
}]
*/

Tests

$ npm test

Contribution

Contributions are appreciated.

License

MIT-licensed. See LICENSE.

Donation

If this project has been helpful in any way, and you want to treat me a cup of coffee, please donate :)

paypal

1.3.1

5 years ago

1.3.0

6 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago