1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 1 1 12 12 51 5 46 12 10 12 2 1 | //2.1 Remove dups from unsorted linked list, recursively var deDupe = function(head) { function start(head) { var current = head; while(current.next != null) { if(head.data === current.next.data) { current.next = current.next.next; //remove dup from list } else { current = current.next; } } if(head.next != null) { start(head.next); } return head; }; return start(head); }; module.exports = deDupe; |