Skip to content

Instantly share code, notes, and snippets.

@mikeliao97
Created February 16, 2017 17:34
Show Gist options
  • Save mikeliao97/719cb891f7aebf4df8a3c8fe3a12f4df to your computer and use it in GitHub Desktop.
Save mikeliao97/719cb891f7aebf4df8a3c8fe3a12f4df to your computer and use it in GitHub Desktop.
var LinkedList = function(value) {
this.value = value;
this.next = null;
}
//REturns a unique linked list based on the argument
function uniqueLinkedList(link_list) {
var uniqueValues = [];
//Iterate through the passed in linked_list
while (link_list) {
if (uniqueValues.indexOf(link_list.value) === -1) {
uniqueValues.push(link_list.value);
}
link_list = link_list.next;
}
//uniqueVAlues = [3, 1, 2]
//REcrate a new linkedList based on the values;
var newLinkedList = new LinkedList();
var pointer = newLinkedList;
while(uniqueValues) {
var toAdd = uniqueValues.shift();
if (typeof pointer === undefined) { //create new one
} else {
pointer = pointer.next;
}
return newLinkedList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment