-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdoubt.js
136 lines (111 loc) · 2.34 KB
/
doubt.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
// assign
let obj1 = {
a: 20
}
let obj2 = {
a: 30
}
let obj = {};
Object.assign(obj, obj1, obj2);
//console.log(obj);
//iteration of arr of objects.
let students = [
{
name: 'Titas',
marks: 90,
courses: ['FE-6', 'BE-5']
},
{
name: 'Vidya',
marks: 99,
courses: ['FE-8', 'BE-2']
},
{
name: 'Shameer',
marks: 97,
courses: ['FE-2', 'BE-9']
}
]
// of
// for(let student of students) {
// console.log(student)
// }
// in
// for(let index in students) {
// console.log(students[index])
// }
// reduce
let arr = [1,2,3,4,5,6,7,8,9];
arr.reduce(function(initializer, curr) {
return initializer+curr;
});
// user authentication.
function User(userName, password) {
this.userName = userName;
this.password = password;
this.login = function(userName, password) {
if(this.userName === userName && this.password === password) {
console.log('auth successful');
} else {
console.log('wrong credentials')
}
}
}
let user1 = new User('titas123', 'titas@987');
user1.login('titas123', 'titas@987')
// console.log(user1)
let arr1 = [1,2,3,4,5,6,7,8,9,10];
let k = 0;
let result = [];
for(let i=0;i<2;i++) {
let insideArr = [];
for(let j=0;j<5;j++) {
insideArr.push(arr1[k]);
k++;
}
result.push(insideArr);
}
let matrix = [
[1, 2, 3, 3],
[9, 8, 7, 6],
[10, 10, 10, 11]
]
function rowWithMaxUnique(matrix) {
let result = {}
for(let i=0;i<matrix.length;i++) {
let insideMatrix = matrix[i];
let tempObj = {};
// create tempObj for every row
/*{
9: 1
8: 1
7: 1
6: 1
}*/
for(let value of insideMatrix) {
if(tempObj[value]) {
tempObj[value] = tempObj[value] +1;
} else {
tempObj[value] = 1;
}
}
let count = 0;
/*
[
[9,1],
[8,1],
[7,1],
[6,1]
]
*/
for(let [key,value] of Object.entries(tempObj)) {
if(value === 1) {
count++;
}
}
result[i] = count;
}
return result;
}
// splice
// spiralMatrix