Class: List

List

new List()

Javascript list implementation
Source:

Methods

find(value) → {Node}

Returns the first node that value matches.
Parameters:
Name Type Description
value any Value to be found
Source:
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.
Source:

get(targetIndex) → {Node}

Retrieves the Node with a given index
Parameters:
Name Type Description
targetIndex number Wanted node's index
Source:
Returns:
Found node
Type
Node

getHead() → {Node}

Returns the head of the list (the first element)
Source:
Returns:
The head node (the first node in the list)
Type
Node

getLength() → {number}

Computes the length of the list
Source:
Returns:
The length of the list.
Type
number

getTail() → {Node}

Returns the tail of the list (the last element)
Source:
Returns:
The tail node (the last node in the list)
Type
Node

getValues() → {Array.<any>}

Converts the list to an array
Source:
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
Source:
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.
Source:
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
Source:
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.
Source:
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
Source:
Returns:
This list. Allows for chainability.
Type
List

List

new List(initialValue)

Creates an instance of List.
Parameters:
Name Type Description
initialValue any Value to initiate the list with.
Source:

Methods

find(value) → {Node}

Returns the first node that value matches.
Parameters:
Name Type Description
value any Value to be found
Source:
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.
Source:

get(targetIndex) → {Node}

Retrieves the Node with a given index
Parameters:
Name Type Description
targetIndex number Wanted node's index
Source:
Returns:
Found node
Type
Node

getHead() → {Node}

Returns the head of the list (the first element)
Source:
Returns:
The head node (the first node in the list)
Type
Node

getLength() → {number}

Computes the length of the list
Source:
Returns:
The length of the list.
Type
number

getTail() → {Node}

Returns the tail of the list (the last element)
Source:
Returns:
The tail node (the last node in the list)
Type
Node

getValues() → {Array.<any>}

Converts the list to an array
Source:
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
Source:
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.
Source:
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
Source:
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.
Source:
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
Source:
Returns:
This list. Allows for chainability.
Type
List