Singly Linked List implemented with JavaScript
append(value)
adds a new node withvalue
to the end of the list.prepend(value)
adds a new node withvalue
to the start of the list.size()
returns the total number of nodes in the list.head()
returns the value of the first node in the list.tail()
returns the value of last node in the list.at(index)
returns the value of the node atindex
. Raises aRangeError
ifindex
is bigger thansize
.pop()
removes the last node from the list.contains(value)
returnstrue
ifvalue
is in the list.find(value)
returns the index of the node containingvalue
, ornull
if not found.toString()
returns string represenation of the list in the following format: ( value ) -> ( value ) -> ( value ) -> null.insertAt(value, index)
inserts a new node withvalue
atindex
. Raises aRangeError
ifindex
is bigger thansize
.removeAt(index)
removes the node atindex
. Raises aRangeError
ifindex
is bigger thansize
.clone()
returns a deep copy of the list.