-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathindex.js
executable file
·374 lines (271 loc) · 7.22 KB
/
index.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/* styling */
require('styles/main.scss');
/* js */
import $ from 'jquery';
import { log, logTitle } from 'logger';
// import { add } from './Math';
/* your imports */
// logTitle('2. Variables')
/* coding examples */
// var name = "Maria Jones";
// var age = 21;
// var hasDriverLicense = true;
// var empty = undefined;
// log(name + " " + "type = " + typeof name);
// log(age + " " + "type = " + typeof age);
// log(hasDriverLicense + " " + "type = " + typeof hasDriverLicense);
// log(empty + " " + "type = " + typeof empty);
// var person = {
// name: "Maria Jones",
// age: 21,
// hasDriverLicense: true,
// dateOfBirth: "01/01/2000",
// address: {
// firstLine: "230 Burham St",
// city: "Cleveland",
// state: "Ohio"
// }
// };
// // log(person+"\n");
// // log(JSON.stringify(person)+"\n")
// // log(person.name+"\n")
// log(JSON.stringify(person.address)+"\n")
// log(Object.values(person)+"\n")
// logTitle('3. Arrays');
// var names = ["Alex", "Maria", "Sam", "Kelly"]
// log(names)
// log(names[0])
// log(names.length)
// for (var n of names) { log(n)}
// for (var n in names) { log(n + " - " + names[n])}
/* or
names.forEach(function(n, index)
{
log(index+ " - "+n)
})
*/
// logTitle('4. Arithmetic Operators');
// var add = 2+3
// var subt = 2-3
// var div = 2/3
// var multi = 2*3
// var rem = 2%3
// log (add)
// log (subt)
// log (div)
// log (multi)
// log (rem)
// logTitle('5. Functions');
// function addNumbers (a,b) {
// return a+b;
// }
// var result = addNumbers(4,5);
// log(result);
// log(Object.keys({name: "Anna", age: 21}));
// log(Object.values({name: "anna", age: 21}))
// /*
// log("OR another method using variable person")
// var person = {name: "anna", age: 21};
// log(Object.keys(person))
// log(Object.values(person))
// */
// log("James Bond".toLowerCase());
// log("James Bond".toLowerCase());
// log("James Bond".startsWith("James"));
// log("James Bond".endsWith("James"));
// logTitle('6. Loops');
// var persons = [
// { name: "Bala", age: 40 },
// { name: "Alex", age: 20 }
// ]
// for ( var i =0; i<=persons.length; i++)
// { log(persons[i].name)
// log(persons[i].age)
// }
// while
// do-while
//break
//continue
//if
// logTitle('7. Switch');
// switch(new Date().getDay()) {
// case 1: log("Monday")
// break;
// case 2: log("Tuesday")
// break;
// case 3: log("wednesday")
// break;
// case 4: log("Thursday")
// break;
// case 5: log("Friday")
// break;
// case 6: log("Saturday")
// break;
// case 0: log("Sunday")
// break;
// }
// logTitle('8. Logical Operators/Type coersion');
// /* ==, !=, <, >, <=, >= */
// log("With type coersion")
// log(typeof 0 + " " + typeof false)
// log(0 == false)
// log(typeof "0" + " " + typeof false)
// log("0" == false)
// log(typeof 1 + " " + typeof "1")
// log(1 == "1")
// log("\n")
// log("Without type coersion")
// log(typeof 0 + " " + typeof false)
// log(0 === false)
// log(typeof "0" + " " + typeof false)
// log("0" === false)
// log(typeof 1 + " " + typeof "1")
// log(1 === "1")
// logTitle('9. Maps | Filter |Reduce')
// var map = [1,2,3,4,5].map(function(n) {
// return n*n;
// })
// log("[].map")
// log(map+"\n");
// var filter = [1,2,3,4,5, 66, 87, 100].filter(function(n) {
// return n%2==0 && n>5
// })
// log("[].filter")
// log(filter+"\n");
// var reduce = [1,2,3,4,5].reduce(function(accumulator, current) {
// return accumulator + current
// })
// log("[].reduce")
// log(reduce+"\n");
// logTitle('10. Callbacks')
// function callbackExample(name, callback) {
// log (callback(name))
// }
// // var callback = function(name) {
// // return "Hello " + name;
// // }
// callbackExample("Anna Maria", function(name) {
// return "Hello " + name;
// })
/* your imports */
// import * as Math from './Math'
// import * as Math from './Math'
// logTitle("11. Named Exports / Imports")
// log(Math.add(8,2))
// log(Math.divide(36,6))
// log(Math.pi)
// /* or if just selective function */
// import {divide, pi} from './Math'
// log(divide(36,6))
// log(pi)
// import Animal from './Animal'
// logTitle("12. Default Exports / Imports");
// var animal = new Animal();
// log(animal.getClassType());
// logTitle("13. Variable Scope & LET");
// // for ( var i =0; i < 10; i++){
// // log(i)
// // }
// // log(i)
// // log("\n")
// for ( let i =0; i < 10; i++){
// log(i)
// }
// log(i)
// log("\n")
// logTitle("14. Const Keyword")
// const person = {};
// person['name'] = "Maria"
// log(person.name)
// const array = []
// array.push('Maria from Array')
// log(array[0])
// logTitle("15. Template Literals")
// let name = 'Anna';
// const age = 22;
// const country = 'USA';
// log ("Name: "+ name + ", Country: " + country + ", Age: " + age )
// log("\n");
// log(`Name: ${name} , Country: ${country.length} , Age: ${age}`);
// let firstName = 'John',
// lastName = 'Doe';
// let greeting = `Hi ${firstName}, ${lastName}`;
// log(greeting)
// log(firstName.length); // Hi John, Doe
// logTitle("16. Spread operator Arrays")
// const arrayOne = ['Maria', 'Anna', 'Alex']
// const arrayTwo = ['Olesi', 'Bahu', 'Serin']
// const concatArray = [...arrayOne, ...arrayTwo]
// concatArray.forEach(function(name) {
// log(name)
// })
// const name = "Bhatawadekar"
// const nametoCharArray = [...name]
// nametoCharArray.forEach(function(letter) {
// log(letter)
// })
// const addNumbers = function(n1,n2,n3,n4,n5,n6,n7){
// return n1+n2+n3+n4+n5+n6+n7
// }
// const numbers = [1,2,3,4,5,6,7]
// const addition = addNumbers(...numbers)
// log(addition)
// logTitle("17. Spread Operator Objects")
// const address = {
// city: 'Detroit',
// country: 'USA',
// zipcode: 48304
// }
// const name = {
// firstName: 'James',
// lastName: 'Bond'
// }
// const person = {...address, ...name}
// log(JSON.stringify(person, null, 2))
// logTitle("18. Arrow Functions")
// const hello = () => {
// const es6 = 'ES6';
// return `Hello ${es6}`;
// };
// const powers = [1,2,3,4,5].map((number, index) => Math.pow(number, index));
// const add = (n1, n2) => n1+n2
// const milesToKm = (miles) => miles * 1.60934;
// log(hello());
// log(powers);
// log(add(100,100));
// log(milesToKm(100));
// logTitle("19. Lexicals this")
// const person = {
// name: 'Alex',
// cars: ['Ferrari', ' Porsche'],
// toString: function() {
// // log(`${this.name} has ${this.cars}`)
// this.cars.forEach( car => {
// log(`${this.name} has ${car}`)
// })
// }
// }
// person.toString()
// logTitle("20. Enhanced Object Properties")
// const pricePropName = "PRICE"
// const calculator = (name, price) => {
// return {
// name,
// /* or add: (n1,n2) => n1+n2 */
// add(n1,n2) { return n1+n2 },
// [pricePropName.toLowerCase()] : price
// }
// }
// const calc = calculator('casio', 19.99)
// log (calc.name)
// log(calc.add(-1,20))
// log(calc.price)
logTitle("21. Array Destructuring")
const names = ['Anna', 'Mariam', 'Joe', 'Mark', 'Matt'];
// const n1 = names[0];
// const n2 = names[1];
// const n3 = names[2];
/* OR */
const [n1, ,n3,...restOfNames] = names;
log(`${n1} ${n3}`);
log(restOfNames)