This mini project forming part of the JavaScript course hosted by The Odin Project. The project provides an opportunity for students to practice implementing one of the new data structures introduced in the previous lessons.
The aim of the project is to implement the following:
- A
NodeClass (or Factory) that represents each node in the linked list. Each node should have:- A value (defaulted to
null) - A link to the next node in the list
- A value (defaulted to
- A
LinkedListClass (or factory) that will represent the full list. - The linked list should have the following functions:
-
append(value): Adds a new node containingvalueto the end of the list. -
prepend(value): Adds a new node containingvalueto the start of the list. -
size: Returns the total number of nodes in the list -
head: Returns the first node in the list -
tail: Returns the last node in the list -
at(index): Returns the node at the givenindex -
pop: Removes the last node from the list -
contains(value): Returns true if the pssed value in the list, false otherwise. -
find(value): Returns the index of the node containing thevalueif it exists in the list. -
toString: Represents the linked list objects as strings. It's formatted to print as:( node-value ) -> ( next-node-value ) -> null
-
- Two extra credit features:
-
insertAt(value, index): Inserts a new node with the providedvalueat the givenindex -
removeAt(index): Removes the node at the givenindex.
-
These are additional features or improvements I think could be made in a future update:
- [] Add a size property to the constructor of the linked list.
- By keeping a rolling counter as the property of the list itself, it would simplify the
sizemethod and could be used to ensure that when the user passes an index to function, that the index isn't larger than the size of the list.
- By keeping a rolling counter as the property of the list itself, it would simplify the
- [] Look to add
tailas a property of the list itself. This way, it can be directly called in thetailandpopmethods as opposed to the current implementation which iterates through the list to find the tail node. - [] Current implementation only allows positive intiger indicies to be used. Look to allow negative indicies where
-1represents thetailnode.