-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetDemo.js
163 lines (112 loc) · 3.14 KB
/
SetDemo.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
////var idSet = new Set();
//var num = Math.round(Math.random()*1000);
//console.log(num);
//var idSet = new Set();
//for (let i = 0; i < 100; i++) {
// idSet.add(Math.round(Math.random() * 1000));
//}
//newset=new Set([...idSet].map(x=>x*1000));
//console.log(idSet);
//var set1=new Set();
//set1.add('HSBC');
//set1.add('HDFC');
//set1.add('IDBI');
//var set2=new Set(['HCL','WIPRO','TCS']);
//console.log('set2',set2);
//var union=new Set([...set1,...set2]);
//console.log(union);
//set1=new Set(['Jaya','Suren','David']);
//set2=new Set(['Jaya','Latha','Anoop']);
//var intersection=new Set([...set1].filter(x=>set2.has(x)));
//console.log(intersection);
//console.log(set2);
//Default Arguments
var countryNames=['India','Indonesia','England','Srilanka'];
function filterDemo(ch='I')
{
//for (let pos in countryNames)
//{
// if(countryNames[pos].startsWith(ch))
// console.log(countryNames[pos]);
//}
//ArrowFunction
//countryNames.forEach((name,i)=>console.log(name,i));
//countryNames.forEach((name,i)=>{
// if(name.startsWith(ch))
// console.log(name,i)
//});
//var result=countryNames.filter(ch);
//console.log(result);
}
filterDemo('E');
//Inbuild filter
var data=[53,78,89,90,55];
function test(value)
{
return value>70;
}
var filterted=data.filter(test);
console.log(filterted);
function testNames(name)
{
return name.startsWith('I');
}
var names=['India','USA','Germany','Singapore'];
//filterted=names.filter(testNames);
//console.log(filterted);
function filterCountry(ch)
{
return function filter(names)
{
return names.startsWith(ch);
};
}
filterted=names.filter(filterCountry());
console.log(filterted);
//Flexi Arguments
function SumUp()
{
var sum=0;
for(let i=0;i<arguments.length;i++)
{
//console.log(typeof(arguments[i]));
if(typeof(arguments[i])=='number')
sum=sum+arguments[i];
//if(typeof(arguments[i])==)
}
console.log(sum);
}
SumUp();
SumUp(34,55);
SumUp(45,67,89,90)
//Closure
var funcExpr=function()
{
var outer=100;
return{
getData:function()
{
return outer;
}
}
}();//immediate invocation
console.log(funcExpr.getData());//console.log(funcExpr().getData());
//CallBack
function flash()
{
console.log('Dashboard updated');
}
setTimeout(flash,5000);
setTimeout(function()
{
console.log('Gold Rates Ready');
},4000);
function reverse(str){
if(str.length<=1){//turminal case
return str;
}
else{
return reverse(str.substr(1))+str[0];
}
}
console.log(reverse("param"));