Skip to content

matthewmueller/frequency-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

frequency-list

Create frequency lists

Example

var FrequencyList = require('frequency-list'),
    list = new FrequencyList;

list.add('hi')
    .add('how are you')
    .add('whats up')
    .add('hi');

list.has('how are you') // true
list.size('hi') // 2
list.size('oh no') // 0

list.remove('hi')
list.unique('hi') // true

Installation

$ component install matthewmueller/frequency-list

API

FrequencyList( [values] )

Initialize the FrequencyList with an optional array of values

#add(str)

Add a word or phrase to the frequency list

#remove(str)

Remove a word or phrase from the frequency list.

#has(str)

Checks to see if a word or phrase exists in the list.

#size(str)

Gets the number of occurences of the given str. If the string is not in the list, the size will be 0.

#unique(str)

Returns true if str occurs exactly once. Alias for size(str) === 1.

#values()

Returns the raw frequency list. You may also use the alias toJSON().

list.values(); //=> { 'hi' : 2, 'how are you' : 1, 'whats up' : 1 }

License

MIT

About

Create frequency lists

Resources

Stars

Watchers

Forks

Packages

No packages published