text: const inspect = require('util').inspect
  
  function Node(val, next) {
    this.val = val
    this.next = next
  }
  
  Node.prototype.hasNext = function () {
    return !!this.next
  }
  
  Node.prototype.hasVal = function () {
    return !!this.val
  }
  
  function LinkedList(head) {
    this.head = head
    this.size = 0
  }
  
  LinkedList.prototype.hasHead = function () {
    return !!this.head
  }
  
  LinkedList.prototype.append = function (val) {
    const node = new Node(val, null)
  
    this.size = this.size + 1
  
    if (!this.hasHead()) {
      this.head = node
      return this.head
    }
    if (!this.head.hasNext()) {
      this.head.next = node
      return this.head
    }
    let currentNode = this.head
    while (currentNode.next !== null) {
      currentNode = currentNode.next
    }
    currentNode.next = node
  
    return currentNode
  }
  
  LinkedList.prototype.removeByVal = function (val) {
    if (this.head.val === val) {
      this.head = this.head.next
      return this.head
    }
    let currentNode = this.head
    while (currentNode.next !== null) {
      if (currentNode.next.val === val) {
        currentNode.next = currentNode.next.next || null
        this.size = this.size - 1
        return
      }
      currentNode = currentNode.next
    }
  }
  
  LinkedList.prototype.setHead = function (val) {
    const newHead = new Node(val, null)
    newHead.next = this.head.next
    this.head = newHead
  
    return newHead
  }
  
  LinkedList.prototype.setTail = function (newTail) {
    this.tail = newTail
  }
  
  LinkedList.prototype.printList = function () {
    let currentNode = this.head
    if (!this.size) {
      return console.log(`List is empty`)
    }
    if (!this.head) console.log('No head.')
    let i = 0
    while (currentNode !== null) {
      console.log(`${i}: val => ${currentNode.val}`)
      currentNode = currentNode.next
      i++
    }
  }
  
  LinkedList.prototype.getSize = function () {
    console.log(`Size: ${this.size}`)
  }
  
  LinkedList.prototype.reverseList = function () {
    if (!this.size) return
  
    let currentNode = this.head
    let tempList = []
    while (currentNode !== null) {
      console.log('currentNode', currentNode.val)
      tempList.push(currentNode)
      currentNode = currentNode.next
    }
    const reversedList = tempList.reverse().map(obj => obj.val)
    console.log('reversed: ', reversedList)
  
    this.head = null
    this.size = 0
  
    for (const item of reversedList) {
      this.append(item)
    }
  }
  
  const linkedList = new LinkedList()
  linkedList.printList()
  linkedList.append(100)
  linkedList.append(255)
  linkedList.append(555)
  linkedList.append(1000)
  linkedList.append(2000)
  linkedList.append(50000)
  linkedList.removeByVal(2000)
  linkedList.printList()
  linkedList.getSize()
  linkedList.append(1)
  linkedList.getSize()
  linkedList.printList()
  
  linkedList.reverseList()
  
  linkedList.printList()
  linkedList.getSize()
  