Methods
find(value) → {Node}
Returns the first node that value matches.
Parameters:
Name | Type | Description |
---|---|---|
value |
any | Value to be found |
Returns:
Node with that value
- Type
- Node
forEach(callbackFn)
Traverses the list and executes the callback function for each element in the list.
The first argument of the callback function is the node's value, the second one is the index.
Parameters:
Name | Type | Description |
---|---|---|
callbackFn |
valueCallbackFn | Function invoked for each element in the list. |
get(targetIndex) → {Node}
Retrieves the Node with a given index
Parameters:
Name | Type | Description |
---|---|---|
targetIndex |
number | Wanted node's index |
Returns:
Found node
- Type
- Node
getHead() → {Node}
Returns the head of the list (the first element)
Returns:
The head node (the first node in the list)
- Type
- Node
getLength() → {number}
Computes the length of the list
Returns:
The length of the list.
- Type
- number
getTail() → {Node}
Returns the tail of the list (the last element)
Returns:
The tail node (the last node in the list)
- Type
- Node
getValues() → {Array.<any>}
Converts the list to an array
Returns:
Array of values from the list
- Type
- Array.<any>
map(callbackFn) → {List}
Executes callbackFn on each item from the list and returns the results as another list.
Parameters:
Name | Type | Description |
---|---|---|
callbackFn |
valueCallbackFn | Function invoked for each element in the list |
Returns:
Transformed list
- Type
- List
push(value, index) → {List}
Adds a value at a given index
Parameters:
Name | Type | Description |
---|---|---|
value |
any | Value to be added. |
index |
number | Index at which the value should be added. |
Throws:
-
Index must not exceed list size.
- Type
- Error
Returns:
This list. Allows for chainability.
- Type
- List
pushBack(newValue) → {List}
Adds a value to the end of the list
Parameters:
Name | Type | Description |
---|---|---|
newValue |
any | A value to be added |
Returns:
This list. Allows for chainability
- Type
- List
reduce(callbackFn, startingValueopt, extractValuesopt) → {any}
Reduces the list to a single value
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callbackFn |
reduceCallbackFN | Callback which reduces the list. | ||
startingValue |
any |
<optional> |
Value to initiate the reducing with. | |
extractValues |
boolean |
<optional> |
true | Decides on what will be passed to the callbackFn, either values or whole nodes. |
Returns:
Reduced value
- Type
- any
remove(valueToRemove) → {List}
Removes nodes with specific values from the list
Parameters:
Name | Type | Description |
---|---|---|
valueToRemove |
any | A value to be removed |
Returns:
This list. Allows for chainability.
- Type
- List