-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14_aug.js
146 lines (110 loc) Β· 2.43 KB
/
14_aug.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
// let car = {
// color: "Black",
// speed: "120kmph",
// brand: "Audi",
// start: function () {
// console.log(`Car started`);
// }
// }
// let newCar = car;
// newCar.brand = "BMW";
// console.log(car);
// let person = {
// name: "shirhaan",
// favFruits: ["π", "π", " π"],
// hobbies: ["π", "π", "π", "π²"],
// address: {
// street: "B. V Road",
// lane: "Vaslane",
// mobileNums: ["1234", "4567", "897"],
// },
// };
// for(let item in person){
// console.log(person[item]);
// }
// higher order function
// let arr = [3, 4, 12, 23, 45, 67];
// arr.push(15);
// arr.indexOf(2);
// function copm(a, b){
// return a-b;
// }
// arr.sort(copm);
// arr.forEach( (a) => {
// console.log(a);
// })
// arr.map();
// arr.forEach()
// arr.filter()
// arr.sort()
// arr.reduce()
// arr.push();
// arr.find();
// arr.pop();
// arr.length;
// why do we need functions ?
// write a function for square of 10 ?
// function square() {
// return 10 * 10;
// }
// write a function for square of 16?
// function squareOf16() {
// return 16 * 16;
// }
// write a function for sqaure of 8;
// function sqaureOf8() {
// return 8 * 8;
// }
// DRY
// function sqaure(inp) {
// return inp * inp;
// }
// sqaure(10);
// write a function which will return sum of 2 values ?
// function solve(a, b) {
// return a + b;
// }
// write a function which will return mutliplaction of 2 values
// function solve(a, b) {
// return a * b;
// }
// function solve(a, b) {
// return a / b;
// }
// function solve(a, b, opration) {
// if (opration == "+") {
// return a + b;
// } else if (opration == "*") {
// return a * b;
// } else {
// return a / b;
// }
// }
// // given an array return new array such that value of element in array is increased by 2;
// let arr = [1, 2, 3, 4];
// // [2, 4, 6, 8]
// // arr1 = [3, 4, 5, 6];
// function solve(arr, op) {
// let ans = [];
// for (let i = 0; i < arr.length; i++) {
// if (op == "+") {
// ans.push(arr[i] + 2);
// } else {
// ans.push(arr[i] * 2);
// }
// }
// return ans;
// }
// function solve(cb) {
// let ans = [];
// for (let i = 0; i < arr.length; i++) {
// ans.push();
// }
// return ans;
// }
// console.log(arr.map((x) => x * 2));
// console.log(solve(arr, "*"));
// arr.forEach( (x) => console.log(x) );
// function solve(arr){
// // return sum of arr element
// }