Last active
August 29, 2015 14:25
-
-
Save EvertonSilva/d0cd295352bce939c11d to your computer and use it in GitHub Desktop.
Convert an Array in a Linked List Object
This file contains 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
/** | |
* Solution to exercise 4.3 | |
* from Eloquent JavaScript Book, | |
* Chapter 4 - Exercise 4.3 | |
* | |
* http://eloquentjavascript.net/04_data.html | |
*/ | |
function arrayToList(arr) { | |
var list = null; | |
for(var i = arr.length - 1; i >= 0; i-- ) { | |
list = {value: arr[i], rest: list}; | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment