Skip to content

Commit 438df66

Browse files
committed
[solution to 4.3] Fix nth to handle the end of a list
1 parent e5dc3f8 commit 438df66

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

code/solutions/04_3_a_list.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ function prepend(value, list) {
1717
}
1818

1919
function nth(list, n) {
20-
if (n == 0)
20+
if (!list)
21+
return undefined;
22+
else if (n == 0)
2123
return list.value;
2224
else
2325
return nth(list.rest, n - 1);

0 commit comments

Comments
 (0)