Skip to content

Instantly share code, notes, and snippets.

@coderaiser
Last active September 28, 2015 07:40
Show Gist options
  • Save coderaiser/b9200482451b643aad0b to your computer and use it in GitHub Desktop.
Save coderaiser/b9200482451b643aad0b to your computer and use it in GitHub Desktop.
function createList(array) {
var list = createNext(0, array);
return list;
}
function createNext(i, array) {
var result;
if (i < array.length) {
result = {
next: createNext(i + 1, array),
data: array[i]
};
}
return result;
}
var list = createList([1,2,3,4]);
function reverse(current) {
var prev, next,
node = current;
while(node) {
next = node.next;
node.next = prev;
prev = node;
node = next;
}
return prev;
}
function createList(array) {
var i = list.length;
while(--i)
list = {
data: array[i],
next: list
};
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment