Skip to content

Commit 7b9f531

Browse files
refactor(aList): remove console.log
1 parent 90b4413 commit 7b9f531

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

chapters/chapter4/aList.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
const arrayToTransform = [1, 2, 3]
2-
const listToTransform = {
3-
value: 1,
4-
rest: {
5-
value: 2,
6-
rest: {
7-
value: 3,
8-
rest: null,
9-
},
10-
},
11-
}
12-
13-
// Part 1
14-
const arrayToList = array => {
1+
export const arrayToList = array => {
152
let list = {}
163
const lastIndex = array.length - 1
174

@@ -25,10 +12,8 @@ const arrayToList = array => {
2512

2613
return list
2714
}
28-
console.log(arrayToList(arrayToTransform)) // => { value: 1, rest: { value: 2, rest: { value: 3, rest: null } } }
2915

30-
// Using while
31-
const listToArray = list => {
16+
export const listToArray = list => {
3217
let initialElement = list
3318
const array = []
3419

@@ -39,21 +24,16 @@ const listToArray = list => {
3924

4025
return array
4126
}
42-
console.log(listToArray(listToTransform)) // [1, 2, 3]
4327

44-
// Part 2
45-
const prepend = (element, list) => {
28+
export const prepend = (element, list) => {
4629
return {
4730
value: element,
4831
rest: list,
4932
}
5033
}
51-
console.log(prepend(0, listToTransform)) // => { value: 0, rest: { value: 1, rest: [Object] } }
5234

53-
// Get an element from the list, recursively.
54-
const nth = (list, number) => {
35+
export const nth = (list, number) => {
5536
if (!list) return 'Element does not exist.'
5637

5738
return number - 1 === 0 && list !== null ? list : nth(list.rest, number - 1)
5839
}
59-
console.log(nth(listToTransform, 3)) // => { value: 3, rest: null }

0 commit comments

Comments
 (0)