JSFiddle - React, Tailwind, and code Playground
by Mike Rispoli
JavaScript
// Your code here.
//eloquent js objects exdcise 3 (cheated a little)
function arrayToList(array){
var list= null;
for (var i = array.length-1; i >= 0; i--) {
list = {value: array[i], rest: list};
}
return(list);
}
function listToArray(list) {
var listArray = [];
for (var node = list; node; node = node.rest) {
listArray.push(node.value);
}
return(listArray);
}
function prepend(value, list) {
var list = {value: value, rest: list};
return(list);
}
function nth(list, value) {
if (value == 0){
return list.value;
} else {
return nth(list.rest, value-1);
}
}