To start off, any kind of prepending and appending methods will need to know where the beginning and end of the linked list
is. Thus, we know we need a head
and tail
reference, so we can start with this snippet as the function constructor.
xxxxxxxxxx
class LinkedList {
constructor() {
this.head = null;
this.tail = null;
}
}
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment