-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (34 loc) · 1.52 KB
/
app.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
//---------------------------------------------------------------Solution #1----------------------------------------------------------------------
var matrixExample = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
function diagnolSum(matrix) {
var sumDiagonals = { PrimaryDiagnol: 0, SecondaryDiagnol: 0 },
matrixLength = matrix.length;
for (var i = 0; i < matrixLength; i++) {
sumDiagonals.PrimaryDiagnol += matrix[i][i];
sumDiagonals.SecondaryDiagnol += matrix[i][matrixLength - i - 1];
}
return sumDiagonals
}
console.log(diagnolSum(matrixExample))
//---------------------------------------------------------------Solution #2----------------------------------------------------------------------
var lst1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
var lst2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for (var i = 0; i < lst1.length; i++) {
console.log(lst1[i] * lst2[i]);
}
//---------------------------------------------------------------Solution #3----------------------------------------------------------------------
var obj = {
parent_name: 'Father',
child1: 'Sumair',
};
var arr = ["Hamza", "Shahbaz", "Jahanzaib", "Junaid", "Tabish", "Ahtisham", "Asghar"]
const finalObj = { ...arr, ...obj }
console.log(finalObj)
//---------------------------------------------------------------Solution #4----------------------------------------------------------------------
fetch(' https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(data => console.log(data));