We will be creating a module that helps us generate a Linked List. A linked list is a data structure that contains nodes. Each node has a value
and a next
property. The value
property contains some data that a user-defined when the node was created. The next
property points to the next node in the list, ergo this is how the nodes are linked.
The last node in a Linked List will have a null
value for the next
property.
{
value: 'Ready Player One',
next: {
value: '1982',
next: {
value: 'Neuromancer',
next: {
value: 'Snow Crash',
next: null
}
}
}
}
Returns the value of the first node of the list
linkedListExample.getHead(); // returns a node object...
{
value: 'Ready Player One'
next: { ... }
}
Returns the value of the last node of a list.
linkedListExample.getTail(); // returns a node object...
{
value: 'Snow Crash',
next: null
}
Takes in any data value and adds a new node to the end of a list. Returns the new node that was created.
linkedListExample.add('The Stranger'); // returns the newly created and appended node...
{
value: 'The Stranger',
next: null
}
Takes in a Number value and searches for the Nth node in a list and returns that node
linkedListExample.get(2); // returns a node object...
{
value: 'Neuromancer',
next: { ... }
}
Takes in a Number value and searches for the Nth node removes it from the list. Should return false
if the the position is outside the length of the list.
linkedListExample.remove(3);
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right.
- Fork this repository and clone it from your personal GitHub Account
- In the Terminal, navigate to the newly created folder for this repository.
- Install dependencies by running the command:
npm install
- Run tests by running the command:
npm test
- Your work will be one in the file named:
linkedList.js
- Pay attention to the tests for hints on what Method names it expects.
- There are no stub descriptions in this exercise.
- Make your tests pass!