2.0 KiB
2.0 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
587d8251367417b2b2512c61 | Work with Nodes in a Linked List | 1 | 301721 |
Description
element
itself, and a reference to the next node
.
Imagine that you are in a conga line. You have your hands on the next person in the line, and the person behind you has their hands on you. You can see the person straight ahead of you, but they are blocking the view of the other people ahead in line. A node is just like a person in a conga line: they know who they are and they can only see the next person in line, but they are not aware of the other people ahead or behind them.
Instructions
Kitten
and Puppy
, and we've manually connected the Kitten
node to the Puppy
node.
Create a Cat
and Dog
node and manually add them to the line.
Tests
tests:
- text: Your <code>Puppy</code> node should have a reference to a <code>Cat</code> node.
testString: assert(Puppy.next.element === "Cat");
- text: Your <code>Cat</code> node should have a reference to a <code>Dog</code> node.
testString: assert(Cat.next.element === "Dog");
Challenge Seed
var Node = function(element) {
this.element = element;
this.next = null;
};
var Kitten = new Node('Kitten');
var Puppy = new Node('Puppy');
Kitten.next = Puppy;
// Only change code below this line
Solution
// solution required