-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (40 loc) · 997 Bytes
/
script.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// currying
const first = () => {
const greet = 'Hi!';
const second = () => {
alert(greet);
}
return second;
}
const newFunc = first();
newFunc();
const multiply = (a, b)-=> a + b;
const curriedMultiply = (a) => (b) => a * b;
// compose
const compose = (f, g) => (a) => f(g(a));
const sum = (num) => num + 1;
compose(sum, sum)(5)
// Advanced Arrays
const array = [1, 2, 10, 16];
const double = []
const newArray = array.forEach(num => {
double.push(num * 2);
})
console.log('forEach', double);
// map, filter, reduce
const mapArray = array.map(num => num * 2);
console.log('map', mapArray);
// filter
const filterArray = array.filter(num => num > 5);
console.log('filter', filterArray);
// reduce
const reduceArray = array.reduce((accumulator, num) => {
return accumulator + num
}, 0);
console.log('reduce', reduceArray);
// debugging
const flattened = [[0, 1], [2, 3], [4, 5]].reduce(
(accumulator, array) => {
debugger;
return accumulator.concat(array)
}, []);