1/**2* Definition for singly-linked list.3* function ListNode(val, next) {4* this.val = (val===undefined ? 0 : val)5* this.next = (next===undefined ? null : next)6* }7*/8/**9* @param {ListNode} head10* @param {number} val11* @return {ListNode}12*/13var removeElements = function (head, val) {14if (!head) return null;1516//if the val is on the beginning delete it17while (head && head.val === val) head = head.next;1819let current = head;20let next = head.next;21//travers the liste and delete any node has this val22while (next) {23if (next.val === val) {24current.next = next.next;25} else current = next;2627next = next.next;28}2930return head;31};