-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
226 lines (201 loc) · 6.94 KB
/
script.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//1.Print odd numbers in an array
//by basic function method
// let arr=[1,2,3,4,5,6,7,8,9,10];
// let oddArr=[];
// function odd(arr){
// for(let i=0;i<arr.length;i++){
// if(arr[i]%2!=0){
// oddArr.push(arr[i])
// }
// }
// return oddArr;
// }
// console.log(odd(arr));
/////////////////////////////////////////////////
//by using Anonymous Function
// let arr1=[1,2,3,4,5,6,7,8,9,10]
// let result=[];
// let oddArr= function(arr){
// for(let i=0;i<arr.length;i++){
// if(arr[i]%2!=0){
// result.push(arr[i])
// }
// }
// return result;
// }
// console.log(oddArr(arr1));
/*-----------------------------------------------------------------*/
//IIFE (Immediately Invoked Function Expression)
// let arr=[1,2,3,4,5,6,7,8,9,10];
// (function odd(arr){
// let oddArr=[];
// for(let i=0;i<arr.length;i++){
// if(arr[i]%2!=0){
// oddArr.push(arr[i])
// }
// }
// console.log(oddArr);
// })
// (arr);
/*///////////////////////////////////////////////////////////*/
//arrow function
// let arr=[1,2,3,4,5,6,7,8,9,10];
// const od= (arr)=>{
// let oddArr=[];
// for(let i=0;i<arr.length;i++){
// if(arr[i]%2!=0){
// oddArr.push(arr[i])
// }
// }
// return oddArr
// }
// console.log(od(arr));
/////////////////////////////////////////////////////////////////////////
//2.Convert all the strings to title caps in a string array
//(i)-function method
// let sArr=["hai","hello","Convert all the strings to title caps in a string array ","ok"];
// function properCase(sArr){
// let newSarr=[];
// for(let i=0;i<sArr.length;i++){
// newSarr.push(sArr[i].charAt(0).toUpperCase()+sArr[i].slice(1).toLowerCase());
// }
// return newSarr
// }
// let result=properCase(sArr);
// console.log(result)
////////////////////////////////////////----------------//////////////////////////////
//2.Convert all the strings to title caps in a string array
//(ii)-by using Anonymous Function
// let sArr=["hai","hello","Convert all the strings to title caps in a string array ","ok"];
// let properCase=function(sArr){
// let newSarr=[];
// for(let i=0;i<sArr.length;i++){
// newSarr.push(sArr[i].charAt(0).toUpperCase()+sArr[i].slice(1).toLowerCase());
// }
// return newSarr
// }
// let result=properCase(sArr);
// console.log(result);
////////////////////////////////////////////////////////////
//2.Convert all the strings to title caps in a string array
//(iii)-by using IIFE (Immediately Invoked Function Expression).
// let sArr=["hai","hello","Convert all the strings to title caps in a string array ","ok"];
// (function properCase(sArr){
// let newSarr=[];
// for(let i=0;i<sArr.length;i++){
// newSarr.push(sArr[i].charAt(0).toUpperCase()+sArr[i].slice(1).toLowerCase());
// }
// console.log(newSarr)
// })
// (sArr)
//////////////////////////////////////---//////////////////////////////////////
//2.Convert all the strings to title caps in a string array
//(iv)-by using arrow function =>.
// let sArr=["hai","hello","Convert all the strings to title caps in a string array ","ok"];
// const properCase=(sArr)=>{
// let newSarr=[];
// for(let i=0;i<sArr.length;i++){
// newSarr.push(sArr[i].charAt(0).toUpperCase()+sArr[i].slice(1).toLowerCase());
// }
// return newSarr
// }
// let result=properCase(sArr);
// console.log(result)
///////////////////.........................////////////////////////////////////////////
//3.Sum of all numbers in an array
//(i)--> using function method
// let a=[1,2,3,5,6,7];
// function sum(num){
// let newnum=0;
// for(let i=0;i<a.length;i++){
// newnum +=a[i]
// }
// return newnum;
// }
// console.log(sum(a))
////,,,,,,,,,,,////////////////////,,,,,,,,,,,,,,,///////////////,,,,,,,,,,,///////////////////
//3.Sum of all numbers in an array
//(ii)-by using Anonymous Function
// let a=[1,2,3,5,6,7];
// let sum=function(num){
// let newnum=0;
// for(let i=0;i<a.length;i++){
// newnum +=a[i]
// }
// return newnum;
// }
// console.log(sum(a))
//-----------------//////////////////////////////////////////------------------/////////////////
//3.Sum of all numbers in an array
//(iii)-by using IIFE (Immediately Invoked Function Expression).
// let a=[1,2,3,5,6,7];
// (function sum(num){
// let newnum=0;
// for(let i=0;i<a.length;i++){
// newnum +=a[i]
// }
// console.log(newnum);
// })
// (a)
//////////////========================================================////////////////////////
//3.Sum of all numbers in an array
//(iv)-by using arrow function =>.
// let a=[1,2,3,5,6,7];
// const sum=(num)=>{
// let newnum=0;
// for(let i=0;i<a.length;i++){
// newnum +=a[i]
// }
// return newnum;
// }
// console.log(sum(a))
/////////////////////;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;//////////////////////
//4.Return all the palindromes in an array
//(i)--> using function method
// let rawData=[121,"dad","liril","hello",757];
// function getplindrmes(rawData){
// let newData=[];
// for(let i=0;i<rawData.length;i++){
// if(rawData[i]==rawData[i].toString().split("").reverse().join("")){
// newData.push(rawData[i])
// }
// } return newData
// }console.log(getplindrmes(rawData))
/////:::::::::::::::::::::::::::::::::?/////////////////////////////////////////////////
//4.Return all the palindromes in an array
//(ii)-by using Anonymous Function
// let rawData=[121,"dad","liril","hello",757];
// let =function(rawData){
// let newData=[];
// for(let i=0;i<rawData.length;i++){
// if(rawData[i]==rawData[i].toString().split("").reverse().join("")){
// newData.push(rawData[i])
// }
// } console.log(newData)
// }
// (rawData);
//////////////////////////+++++++++++++++++++++++==////////////////////////////
//4.Return all the palindromes in an array
//(iii)-by using IIFE (Immediately Invoked Function Expression).
// let rawData=[121,"dad","liril","hello",757];
// (function getplindrmes(rawData){
// let newData=[];
// for(let i=0;i<rawData.length;i++){
// if(rawData[i]==rawData[i].toString().split("").reverse().join("")){
// newData.push(rawData[i]) }
// } console.log(newData)
// })
// (rawData);
////////////////////////////.................................///////////////////////////////
//4.Return all the palindromes in an array
//(iv)-by using arrow function =>.
// let rawData=[121,"dad","liril","hello",757];
// const getplindrmes=(rawData)=>{
// let newData=[];
// for(let i=0;i<rawData.length;i++){
// if(rawData[i]==rawData[i].toString().split("").reverse().join("")){
// newData.push(rawData[i])
// }
// } return newData
// }
// console.log(getplindrmes(rawData))