function arrayToList(array) {
    let list = null;
    for (let i = array.length - 1; i >= 0; --i) {
        list = {value: array[i], rest: list};
    }
    return list;
}

function listToArray(list) {
    let array = [];
    for (let node = list; node; node = node.rest) {
        array.push(node.value);
    }
    return array;
}

function prepend(element, list) {
    return {element, rest: list};
}

function nth(list, n) {
    // Could check if (!list) here instead or in the return expression
    if (n === 0) return list.value;
    else return list.rest ? nth(list.rest, n-1) : undefined;
}

@@ -21,18 +21,49 @@
 (arr
-ay
 ) %7B%0A
-    
+%09if (arr.length == 0) return null;%0A%0A%09
 let 
@@ -75,20 +75,17 @@
 = null;%0A
-    
+%09
 for (let
@@ -92,18 +92,16 @@
  i = arr
-ay
 .length 
@@ -120,24 +120,18 @@
  --i) %7B%0A
-        
+%09%09
 list = %7B
@@ -140,18 +140,16 @@
 lue: arr
-ay
 %5Bi%5D, res
@@ -158,26 +158,21 @@
  list%7D;%0A
-    %7D%0A    
+%09%7D%0A%0A%09
 return l
@@ -212,32 +212,25 @@
 ) %7B%0A
-    
+%09
 let arr
-ay
  = %5B%5D;%0A
-    
+%0A%09
 for 
@@ -277,21 +277,13 @@
 ) %7B%0A
-        
+%09%09
 arr
-ay
 .pus
@@ -299,20 +299,14 @@
 lue)
-;%0A    %7D%0A    
+%0A%09%7D%0A%0A%09
 retu
@@ -311,18 +311,16 @@
 turn arr
-ay
 ;%0A%7D%0A%0Afun
@@ -337,19 +337,16 @@
 end(elem
-ent
 , list) 
@@ -351,20 +351,17 @@
 ) %7B%0A
-    
+%09
 return %7B
 elem
@@ -360,15 +360,19 @@
 rn %7B
+value: 
 elem
-ent
 , re
@@ -413,91 +413,17 @@
 ) %7B%0A
-    // Could check if (!list) here instead or in the return expression%0A    
+%09
 if (n ==
 = 0)
@@ -418,21 +418,24 @@
 if (n ==
-=
  0) 
+%7B%0A%09%09
 return l
@@ -449,35 +449,69 @@
 ue;%0A
-    else return list.rest ?
+%09%7D%0A%0A%09if (list.rest == null) %7B%0A%09%09return undefined;%0A%09%7D%0A%0A%09return
  nth
@@ -527,23 +527,12 @@
 t, n
+ 
 -1)
- : undefined
 ;%0A%7D%0A

Add chapter 4, exercise 3