Skip to content

Instantly share code, notes, and snippets.

@AntonisFK
Created April 28, 2016 00:21
Show Gist options
  • Save AntonisFK/981e06b656176dbab9551253d04111d7 to your computer and use it in GitHub Desktop.
Save AntonisFK/981e06b656176dbab9551253d04111d7 to your computer and use it in GitHub Desktop.
Removing duplicates from an unsorted link list
function removeDuplicates(SSL){
if(this.head === null){
return false;
}else {
var current = this.head;
var obj = {};
while(current.next !== null){
// going to use an object to check if
if(current.next.value in obj){
//we are going to do the swap
current.next = current.next.next;
}
// create a key with the value, rememeber there can not be duplicate keys
obj[current.value] = 1;
//traverse down the link list
current = current.next;
}
}
return SSL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment