📅  最后修改于: 2022-03-11 15:03:24.338000             🧑  作者: Mango
// Day 15: Linked List hackerrank javascript solution
this.insert = function (head, data) {
//complete this method
let newNode = new Node(data);
if (head === null || typeof head === "undefined") {
head = newNode;
} else if (head.next === null) {
head.next = newNode;
} else {
let nextValue = head.next;
while (nextValue.next) {
nextValue = nextValue.next;
}
nextValue.next = newNode;
}
return head;
};