generated from docsifyjs/docsify-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathothers-mainstream.js
67 lines (53 loc) · 1.23 KB
/
others-mainstream.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
61
62
63
64
65
66
67
/// [function]
function say(text) {
console.log(text);
return true;
}
/// [function]
/// [anonFunction]
say2 = (x) => { console.log(x); return true; };
/// [anonFunction]
/// [ifElse]
if (true) {
say("it is true");
} else {
say("it is not true");
}
/// [ifElse]
/// [loops]
for (var i of [1, 2, 3, 4, 5]) {
say(i);
}
for (var i = 1; i <= 5; i++) {
say(i);
}
while (true) {
say("this is an infinite loop");
}
/// [loops]
/// [short]
true && say("it is true") || say("it is not true")
/// [short]
/// [recursion]
function while_loop() {
say("yes") && true && while_loop();
}
function for_loop(i) {
i++;
say(i);
(i == 5) || for_loop(i);
}
for_loop(0) // <1>
while_loop() // <2>
// (1) execute for-loop first
// (2) since the while-loop will enter an infinite loop,
// you will need to cancel the execution by pressing CTRL-C
/// [recursion]
/// [mapReduce]
const numbers = [1, 2, 3, 4, 5];
say(numbers.map(i => i * 3));
say(numbers.filter(i => i % 2));
say(numbers.reduce((a,b) => a + b ));
/// [mapReduce]
// * properties, methods
myObject = { myProperty: "name", myMethod: (x) => "name"; }