Challenge Name
Add Elements at a Specific Index in a Linked List has an issue.
Issue Description
This code definitely does not add an element at a given index. Suddenly, it have passed all the tests.
Browser Information
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3158.0 Safari/537.36
.
Screenshot
Your Code
this.addAt = function(index, element) {
var currentNode = head;
var previousNode;
var node = new Node(element);
if(index > length || index < 0) {
return false;
} else if(index === 0) {
node.next = head;
head = node;
}
length++;
};