Skip to content

Instantly share code, notes, and snippets.

@bertoort
Created August 30, 2016 06:16
Show Gist options
  • Save bertoort/45fa355064b9bb8eb6c8905e7201ffef to your computer and use it in GitHub Desktop.
Save bertoort/45fa355064b9bb8eb6c8905e7201ffef to your computer and use it in GitHub Desktop.
Recursion Warm Up
function Node(data) {
this.data = data;
this.next = null;
}
function LinkedList() {
this.length = 0;
this.head = null;
}
LinkedList.prototype.add = function(value) {
var node = new Node(value);
var currentNode = this.head;
this.length++;
if (!currentNode) {
this.head = node;
return
}
// TODO change while loop to recursion
while (currentNode.next) {
currentNode = currentNode.next;
}
currentNode.next = node;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment