Constructor
new CountedList(objs, source)
Parameters:
Name | Type | Description |
---|---|---|
objs |
Array of objects to initialize the list with. | |
source |
CountedListSource | Source of the list (for logging/context). |
Properties:
Name | Type | Description |
---|---|---|
length |
number | The number of objects in the list.* |
logger |
Logger | Logger instance for this list. |
maxNumToots |
number | undefined | The maximum numToots value in the list.* |
nameDict |
Record.<string, T> | Dictionary mapping object names to objects. |
objs |
Array.<T> | The array of objects in the list. |
source |
ListSource | The source of the list (for logging/context). |
Members
objs
Has side effect of mutating the 'nameDict' property.
Methods
addObjs(objs)
Add objects we don't already have. This does NOT set the numToots property on incoming objs!
Parameters:
Name | Type | Description |
---|---|---|
objs |
Array.<T> | Array of objects to add to the list. |
filter(predicate) → {module:api/counted_list~CountedList.<T>}
Like the standard Array.filter().
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | Function to test each object in the list. |
Returns:
A new CountedList containing only the objects that match the predicate.
- Type
- module:api/counted_list~CountedList.<T>
forEach()
Standard Array.forEach() approximation that invokes a callback for each object in the objs array.
getObj(name) → {T|undefined}
Returns the object in the list with the given name (case-insensitive) if it exists.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the object to retrieve. |
Returns:
The object with the specified name, or undefined if not found.
- Type
- T | undefined
incrementCount(name, newObjDecoratoropt) → {T}
Increment numToots for the given 'name'. If no obj with 'name' exists create a new one
and call newObjDecorator() to get its properties.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | The name of the object to increment. | |
newObjDecorator |
function |
<optional> |
Optional function to decorate the new object with additional properties. |
Returns:
The object with the incremented numToots.
- Type
- T
map()
Standard map function that applies a callback to each object in the objs array.
maxValue(propertyName) → {number|undefined}
Get the maximum value for a given key across the objs array
Parameters:
Name | Type | Description |
---|---|---|
propertyName |
Returns:
The maximum value for the specified property, or undefined if none exist.
- Type
- number | undefined
nameToNumTootsDict() → {StringNumberDict}
Returns a dict of 'obj.name' to 'obj.numToots'.
Returns:
Dictionary mapping object names to their numToots counts.
- Type
- StringNumberDict
populateByCountingProps(objs, propExtractor)
Populate the objs array by counting the number of times each 'name' (given by propExtractor) appears.
Resulting BooleanFilterOptions will be decorated with properties returned by propExtractor().
Parameters:
Name | Type | Description |
---|---|---|
objs |
Array.<U> | Array of objects to count properties from. |
propExtractor |
function | Function to extract the decorator properties for the counted objects. |
removeKeywords(keywords)
Remove any obj whose 'name' is watches any of 'keywords'.
Parameters:
Name | Type | Description |
---|---|---|
keywords |
Array.<string> | Array of keywords to match against the object's name. |
topObjs(maxObjsopt) → {Array.<T>}
Returns the objs in the list sorted by numAccounts if it exists, otherwise by numToots,
and then by name. If maxObjs is provided, returns only the top maxObjs objects.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
maxObjs |
number |
<optional> |
Optional maximum number of objects to return. |
Returns:
Objects sorted by numAccounts if it exists, otherwise numToots, then by name
- Type
- Array.<T>