Open zhutoutoutousan opened 4 years ago
@zhutoutoutousan sir apologies but i see it correct. once the line a.append(5) gets executed there is nothing in the linkedList so the '5' becomes the head value and then the 7 will be appended so added to the next node's value.
see below image, the head has value of 5
just wanted to understand your view point, may be there is some bug that I am not observing. let me know. I would be very much interested in this
How to recreate the problem
console.log
to theappend()
method.let a = new LinkedList(); a.append(5) a.append(7) // In the
append
method, it wasthis.tail = newNode
, but in chrome console, // it can be observed that it was added to head.// If I changed the
this.tail = newNode
tothis.head = newNode
, it appended to the tail// If I add some
console.log
in theappend
method, // it could be observed that the class instance is already been changed // before theconsole.log
was reached(applies even whenconsole.log
is at the start of themethod
.