-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.js
43 lines (35 loc) · 912 Bytes
/
transform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { timeIt, arrayOfRandoms, multiplyByThree, isEven } = require('./utils.js')
const arrayOfThousand = arrayOfRandoms(100)(1e3)
const arrayOfMillion = arrayOfRandoms(100)(1e7)
// Declarative Transformations
timeIt('Thousands -> map', () => {
arrayOfThousand
.map(multiplyByThree)
})
timeIt('Millions -> map', () => {
arrayOfMillion
.map(multiplyByThree)
})
timeIt('Thousands -> map & filter', () => {
arrayOfThousand
.map(multiplyByThree)
.filter(isEven)
})
timeIt('Millions -> map & filter', () => {
arrayOfMillion
.map(multiplyByThree)
.filter(isEven)
})
// Imperative Transformations
timeIt('Millions -> map & filter (Imperative)', () => {
const result = []
arrayOfMillion
.forEach(
x => {
const value = multiplyByThree(x)
if(isEven(value)) {
result.push(value)
}
}
)
})