Code coverage report for lib/algorithms/2-linkedLists/deDupe.js

Statements: 100% (11 / 11)      Branches: 100% (2 / 2)      Functions: 100% (1 / 1)      Lines: 100% (11 / 11)      Ignored: none     

All files » lib/algorithms/2-linkedLists/ » deDupe.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21      1 2 2 2   2 15 5   10 10       2     1
//2.1 Remove dups from unsorted linked list
//this implementation only works for numbers
 
var deDupe = function(head) {
	var items = [];
	var current = head;
	items[current.data] = true;
 
	while(current.next != null) {
		if(items[current.next.data]) {
			current.next = current.next.next; //remove dup from list
		} else {
			items[current.next.data] = true;
			current = current.next;
		}
	}
 
	return head;
};
 
module.exports = deDupe;