Skip to content

Commit 365641c

Browse files
committed
Section 32: Test Driven Development pt2 DONE
1 parent 7db9933 commit 365641c

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

32-The-Basics-of-Testing/02-hidash/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ module.exports = {
44
fn(arr[index], index)
55
}
66
},
7-
}
7+
map(arr, fn) {
8+
const result = []
9+
for (let i = 0; i < arr.length; i++) {
10+
result.push(fn(arr[i], i))
11+
}
12+
13+
return result
14+
},
15+
}
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
const { forEach, map } = require('./index')
22

3-
let sum = 0
4-
forEach([1, 2, 3], (value) => {
5-
sum += value
3+
// let sum = 0
4+
// forEach([1, 2, 3], (value) => {
5+
// sum += value
6+
// })
7+
8+
// console.log(sum)
9+
10+
// if (sum !== 6) {
11+
// throw new Error('Expected summing array to equal 6')
12+
// }
13+
14+
const result = map([1, 2, 3], (value) => {
15+
return value * 2
616
})
17+
// result === [2, 4, 6]
718

8-
console.log(sum)
19+
if (result[0] !== 2) {
20+
throw new Error(`Expected to find 2, but found ${result[0]}`)
21+
}
22+
23+
if (result[1] !== 4) {
24+
throw new Error(`Expected to find 4, but found ${result[1]}`)
25+
}
926

10-
if(sum !== 6) {
11-
throw new Error('Expected summing array to equal 6')
27+
if (result[2] !== 6) {
28+
throw new Error(`Expected to find 6, but found ${result[2]}`)
1229
}

0 commit comments

Comments
 (0)