-
-
Save tarzak/d4e74fe2052e02543f1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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