I've been poking around and I can't seem to find an answer to this question.
I have a linked list that I need to access when certain objects on my page are clicked. I made a get(id) method that loops through this linked list until it finds the node matching the id. At the moment there are 3 items in my list and therefore ids 0, 1, and 2. The set method manipulates html on the page based off of information from the linked list.
Here is the code for my click listener where secondaryFeatured is an array of JQuery objects:
for(var i = 0; i < secondaryFeatured.length; i++) {
secondaryFeatured[i].click(function() {
set(list.get(i));
});
}
DoubleLinkedList.prototype.get = function(id) {
while(this.head.id != id) {
this.next();
}
return this.head;
}
When I click it gets stuck in an infinite loop in my get function searching for the id "3" when there are only 3 objects in my (last object has index of 2).