-
Notifications
You must be signed in to change notification settings - Fork 9
/
May_20.js
131 lines (95 loc) · 2.31 KB
/
May_20.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
// var person = {
// name : "Dishi",
// age : 24,
// sibling : ["Mehak"],
// isStudent : true
// }
// Object.seal(person)
// console.log(Object.isSealed(person))
// person.name="Deepanshu"
// console.log(person)
// person.test = "test"
// console.log(person)
// delete person.age;
// console.log(person)
// //can not delete
// //can not add
// //can modify
// var person = {
// name : "Dishi",
// age : 24,
// sibling : ["Mehak"],
// isStudent : true
// }
// Object.preventExtensions(person)
// console.log(Object.isExtensible(person))
// person.name = "Deepanshu"
// console.log(person)
// person.test = "test"
// console.log(person)
// delete person.name
// console.log(person)
// //can delete
// //can update
// //can not add
// const arr = [5,1,2,6]
// function double(x){
// return x*2;
// }
// function triple(x){
// return x*3;
// }
// function add5(x){
// return x+5;
// }
// const output = arr.map(add5)
// console.log(output)
// // ===============FILTER================
// const arr = [5,1,2,6]
// function odd(x){
// return x%2;
// }
// function even(x){
// return x%2===0;
// }
// const output = arr.filter((x)=>x%2===0)
// console.log(output)
// //filter will accept a function which will basically filters out the existing values and give new values
// ///REDUCE/////////
// const arr = [5,1,2,6,8,9]
// function findSum(arr){
// let sum = 0;
// for(let i=0;i<arr.length;i++){
// sum= sum + arr[i]
// }
// return sum;
// }
// //same using reduce
// const output = arr.reduce(function(acc,curr){
// acc = acc+curr;
// return acc;
// },0)
// console.log(output)
// //pass function which will do our job
// //this function will be iterated to each and every element of an array
// // acc - accumulator - it will add or accumulate the reult after each iteration , just as sum
// // curr - current - represents the value in each iteration , just as arr[i]
// //Reduce
// const arr = [5,1,2,6,8,9] //9
// function findMax(arr){
// let max = 0;
// for(let i =0;i<arr.length;i++){
// if(arr[i]>max){
// max=arr[i]
// }
// }
// return max;
// }
// const output = arr.reduce(function(max,curr){
// if(curr>max){
// max= curr;
// }
// return max;
// },0)
// console.log(arr)
// console.log(output)