/*method to reverse a linked list */
reverse(list) {
let current = list.head;
let prev = null;
let next = null;
if (this.head) {
//only one node
if (!this.head.next) { return this; }
while (current) {
next = current.next;//store next node of current before change
current.next = prev;//change next of current by reverse the link
prev = current;//move prev node forward
current = next;//move current node forward
}
list.head = prev
return list
}
return "is empty"
}