Bag
A simple collection class to contain unique, keyed items.
Properties
2
Properties
2Functions
12
Functions
12Adds the passed item(s) to this Bag. Existing items with the same ID will be replaced.
| Parameter | Type | Description |
|---|---|---|
toAdd | Object | Object[] | Item(s) to add. |
Returns nth item in this Bag.
| Parameter | Type | Description |
|---|---|---|
nth | Number | The index of the matching item. Negative numbers index for the last item. For example, -1 returns the last item, -2 the 2nd to last item etc. |
The matched item, or undefined.
Change the id of an existing member by mutating its idProperty.
| Parameter | Type | Description |
|---|---|---|
item | String | Number | Object | The item or id of the item to change. |
newId | String | Number | The id to set in the existing member. |
Returns the number of items in this Bag which elicits a truthy return value from the passed function.
| Parameter | Type | Description |
|---|---|---|
fn | function | A function, which, when passed an item, returns |
The number of matched items.
Extracts the matching items from this Bag into an array based upon the passed value filter function.
| Parameter | Type | Description |
|---|---|---|
fn | function | A function, which, when passed an item, returns a |
thisObj | Object | The |
An array of values extracted from this Bag.
Returns nth item in this Bag which elicits a truthy return value from the provided matcher function fn.
| Parameter | Type | Description |
|---|---|---|
fn | function | A function which, when passed an item, returns |
nth | Number | The index of the matching item. By default, 0 returns the first item that matches
according to |
The matched item, or undefined.
Executes the passed function for each item in this Bag, passing in the item.
| Parameter | Type | Description |
|---|---|---|
fn | function | The function to execute. |
thisObj | Object | The |
Returns the item with the passed id.
| Parameter | Type | Description |
|---|---|---|
id | * | The |
The found item, or undefined.
Returns true if this Collection includes an item with the same id as the passed item.
| Parameter | Type | Description |
|---|---|---|
item | Object | String | Number | The item to find, or an |
True if the passed item is found.
Extracts the content of this Bag into an array based upon the passed value extraction function.
| Parameter | Type | Description |
|---|---|---|
fn | function | A function, which, when passed an item, returns a value to place into the resulting array. |
thisObj | Object | The |
An array of values extracted from this Bag.
Removes the passed item(s) from this Bag.
| Parameter | Type | Description |
|---|---|---|
toRemove | Object | Object[] | Item(s) to remove. |
Sort the values of this Bag using the passed comparison function.
Setting this property replaces the data set.
| Parameter | Type | Description |
|---|---|---|
fn | function | Comparison function which returns -ve, 0, or +ve |