Class: List

List

Very simple Array-backed List implementation.
It is discouraged the use of this class to handle big lists.

new List()

Creates an empty List instance

Method Summary

add
Adds the element to the end of the list (using Array.
asArray
Returns a copy of the internal array.
clean
Resets the list by re-instantiating the internal array.
contains
Checks if an element is in the list
forEach
Executes a given callback passing each element of the list as the only call parameter.
remove
Removes the first occurrence of the specified object in the List.

Method Detail

add(newEl)

Adds the element to the end of the list (using Array.push). Each element can be added multiple times; in such case it will be added to the list multiple times
Parameters:
Name Type Description
newEl Object The element to be added

asArray() → {Array}

Returns a copy of the internal array.
Returns:
A copy of the original array.
Type
Array

clean()

Resets the list by re-instantiating the internal array.

contains(el) → {Boolean}

Checks if an element is in the list
Parameters:
Name Type Description
el Object the element to be searched
Returns:
true if element was found, false otherwise
Type
Boolean

forEach(cb)

Executes a given callback passing each element of the list as the only call parameter.
Callbacks are executed synchronously before the method returns: calling List#add or List#remove during callback execution may result in a wrong iteration.
Parameters:
Name Type Description
cb function The callback to be called.

remove(newEl) → {Boolean}

Removes the first occurrence of the specified object in the List.
A linear search is performed to find the element; a non-strict comparison ( == ) is performed to identify the element.
Parameters:
Name Type Description
newEl Object The element to be removed
Returns:
true if element was found and deleted, false otherwise
Type
Boolean