function ListNode(val) {
this.val = val;
this.next = null;
}
var list = (function createLinkedList(...args) {
const reverseArgs = args.reverse()
const tmplistNode = new ListNode(0)
let length = reverseArgs.length
let cur = new ListNode(reverseArgs[length - 1])
tmplistNode.next = cur
while (length-- && length >= 1) {
let next = new ListNode(reverseArgs[length - 1])
cur.next = next
cur = next
}
return tmplistNode.next
})(1, 2, 3, 4, 5)
var printList = function (list) {
let cur = list
let str = ''
while (cur) {
str += `${cur.val} -> `;
cur = cur.next
cur === null && (str += 'null')
}
console.log(str)
}