Created
December 31, 2017 16:06
-
-
Save garybunofsky/5edc13bd5f4b8b7482e0a93b0d7d32e5 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/hupaja
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Eloquent Javascript: 04 Data Structures, Array to List</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var arrayToList = function(array) { | |
var list = {}; | |
for(var i = 0; i <= array.length; i++){ | |
console.log(i); | |
if (i === 0) { | |
list = {value: array[array.length - i]}; | |
} else { | |
list = {value: array[array.length - i], rest: list}; | |
} | |
} | |
return list; | |
} | |
console.log(arrayToList([1,2,3])); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var arrayToList = function(array) { | |
var list = {}; | |
for(var i = 0; i <= array.length; i++){ | |
console.log(i); | |
if (i === 0) { | |
list = {value: array[array.length - i]}; | |
} else { | |
list = {value: array[array.length - i], rest: list}; | |
} | |
} | |
return list; | |
} | |
console.log(arrayToList([1,2,3]));</script></body> | |
</html> |
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
var arrayToList = function(array) { | |
var list = {}; | |
for(var i = 0; i <= array.length; i++){ | |
console.log(i); | |
if (i === 0) { | |
list = {value: array[array.length - i]}; | |
} else { | |
list = {value: array[array.length - i], rest: list}; | |
} | |
} | |
return list; | |
} | |
console.log(arrayToList([1,2,3])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment