Created
August 30, 2016 06:16
-
-
Save bertoort/45fa355064b9bb8eb6c8905e7201ffef to your computer and use it in GitHub Desktop.
Recursion Warm Up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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