-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (40 loc) · 918 Bytes
/
index.js
File metadata and controls
54 lines (40 loc) · 918 Bytes
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
const add = (x) => {
// Add your code below this line
return (y) => {
return (z) => {
return x + y + z
}
}
// Add your code above this line
}
console.log(add(10)(20)(30))
// Currying and Partial Function Application
const volume = (l) => {
return (w, h) => {
return l * w * h
}
}
console.log(volume(70)(203, 142))
// also can be called in this way
// because hCy is just a declaration of anonimous function
// that returned by volume
// it is just (w, h) => {
// return l * w * h
// }
// it works becouse l comes from cloasure
const hCy = volume(70)
console.log(hCy(203, 142))
// example 3
const multiply = (x) => {
return (y) => {
return (z) => {
return x * y * z
}
}
}
console.log(multiply(2)(3)(4))
const mult1 = multiply(2)
const mult2 = mult1(3)
const mult3 = mult2(4)
// save as console above console.log(multiply(2)(3)(4))
console.log(mult3)