Linked List
The sixth project of the JavaScript course from The Odin Project.
Documentation
Node
Constructor
Node(value?, nextNode?)
value
and nextNode
are both optional and set to null
by default.
Properties
value
Returns the value in the node.
nextNode
Returns the next node.
LinkedList
Constructor
LinkedList(value?)
value
is optional and set to null
by default.
Properties
size
Returns the total number of nodes in the list.
head
Returns the first node of the list.
tail
Returns the last node of the list.
Methods
append
append(value)
Adds a new node containing value
to the end of the list.
Returns undefined
.
prepend
prepend(value)
Adds a new node containing value
to the start of the list.
Returns undefined
.
insertAt
insertAt(value, index)
Inserts a new node containing value
at the given index
.
Returns undefined
.
shift
shift()
Removes the first node from the list. Returns the removed node.
pop
pop()
Removes the last node from the list. Returns the removed node.
removeAt
removeAt(index)
Removes the node at the given index
.
Returns the removed node.
at
at(index)
Returns the node at the given index
.
contains
contains(value)
Returns true
if the passed value
is in the list, otherwise, returns false
.
find
find(value)
Returns the index of the node containing value
, or null
if not in the list.
toArray
toArray()
Converts the list into an array then returns it.
toString
toString()
Returns a string representation of the list.
Syntax: ( value ) -> ... -> ( value ) -> null