Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjarneo/most-common
Get the _n_ most common elements and their counts from the most common to the least.
https://github.com/bjarneo/most-common
nlp words
Last synced: 3 days ago
JSON representation
Get the _n_ most common elements and their counts from the most common to the least.
- Host: GitHub
- URL: https://github.com/bjarneo/most-common
- Owner: bjarneo
- License: mit
- Created: 2017-03-15T18:24:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-24T16:00:28.000Z (over 5 years ago)
- Last Synced: 2024-10-08T02:50:33.435Z (about 1 month ago)
- Topics: nlp, words
- Language: JavaScript
- Size: 16.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
most-common
--
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4JDQMB6MRJXQE&source=url)
![Travis](https://travis-ci.org/bjarneo/most-common.svg?branch=master)Get the _n_ most common elements and their counts from the most common to the least.
Usage
--```bash
$ npm i --save most-common
``````js
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
--
```bash
$ 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](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4JDQMB6MRJXQE&source=url)