-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice.js
86 lines (70 loc) · 1.55 KB
/
practice.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// print loop after each second
for (let i = 1; i <= 5; i++) {
setTimeout(function () {
console.log(i);
}, i * 1000);
}
// print loop after each second
for (var i = 1; i <= 5; i++) {
function close(x) {
setTimeout(function () {
console.log(x);
}, x * 1000);
}
close(i);
}
// function statement aka function declaration
function a() {
console.log("a is called");
}
// function expression
var b = function() {
console.log("b is called")
}
// anonymous function
// function() {
// }
// named function expression
var b = function a() {
}
// first class functions
var a = function (x) {
console.log("First class function");
};
a(function () {});
// callback function
function x(y) {
console.log("x");
y();
}
x(function y() {
console.log("y");
});
function reverseString(str) {
if (str === "") return "";
else return reverseString(str.substr(1)) + str.charAt(0);
}
console.log(reverseString("Welcome to this Javascript"));
function Reverse(str) {
if (str === null) {
return null;
}
if (str.length <= 1) {
return str;
}
var first = str[0];
var last = str[str.length - 1];
var str1 = Reverse(str.substring(1, str.length - 1));
return last + str1 + first;
}
var result = Reverse("Welcome to this Javascript");
console.log(result)
let str = "Welcome to this Javascript";
function reverseString(str) {
function reverse(str) {
if (str === "") return "";
else return reverse(str.substr(1)) + str.charAt(0);
}
return reverse(str).split(" ").reverse().join(" ");
}
console.log(reverseString(str));