-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemple.js
More file actions
60 lines (44 loc) · 1.21 KB
/
semple.js
File metadata and controls
60 lines (44 loc) · 1.21 KB
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
// // const obj = {
// // name: "bobby",
// // experience: 100,
// // wizard: false
// // }
// // const player = obj.name;
// // const experience = obj.experience;
// // let wizard = obj.wizard;
// // const { player, experience } = obj;
// // ===============
// // const name = 'John Snow';
// // const obj = {
// // [name]: "hello",
// // [1 + 2]: 'hihi'
// // }
// // const name = "sally";
// // const age = 34;
// // const pet = 'horse';
// // const bestGreeting = `Hello ${name}, you look ${age - 10}. What a lovely ${pet}.`;
// function greet(name = '', age = 30, pet = "cat") {
// `Hello ${name}, you look ${age - 10}. What a lovely ${pet}.`;
// }
// function add(a, b) {
// return a + b;
// }
// const add = (a, b) => a + b;
const first = () => {
const greet = 'Hi';
const second = () => {
alert(greet);
}
return second;
}
const newFunc = first();
newFunc();
// Currying
const multiply = (a, b) => a * b;
const curriedMultiply = (a) => (b) => a * b;
// Compose
const compose = (f, g) => (a) => f(g(a));
const increment = (num) => num + 1;
compose(increment, increment)(5);
// returns 7 increment(increment(5));
// functional purity and avoiding side effects