-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
112 lines (88 loc) · 2.32 KB
/
Copy pathmain.js
File metadata and controls
112 lines (88 loc) · 2.32 KB
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
/*
0 Алгоритмы
Реализуйте функцию которая будет превращать трехмерный массив
в двухмерный, а если массив двухмерный, тогда в трехмерный массив
ИСПОЛЬЗУЙТЕ МЕТОДЫ МАССИВОВ !
*/
solution = arr => {
let counter = 0;
let resultArray = [];
while (counter != arr[0].length) {
let smallArray = arr.map(item => { // [1, 'a']
return item[counter];
})
resultArray.push(smallArray);
counter++;
}
return resultArray;
}
//console.log(solution([ [1, 'a'], [2, 'b'], [3, 'c'] ])) //=> [ [1, 2, 3], [a, b, c] ];
//console.log(solution([ [1, 3, 5], [2, 4, 6] ])) //=> [ [1, 2], [3, 4], [5, 6] ];
//console.log(solution([[]]))// => []
//console.log(solution([ [ [ ] ] ])) // = [ [] ]
//----------------------------------------------------------------------
/*
/*
<h1>Main</h1>/////
<ul>
<h1>Catalog</h1>////
<li>
<ul>
<h1>Comp</h1>////
<ul>
<li>
<h1>Notebook</h1>
<h1>...</h1>
</li>
</ul>
</li>
Визуализируйте массив, если в коллекции есть свойство
children,
тогда создайте вложенный лист
name - свойство h1
children ul -> li
Используйте innerHTML
*/
const navigation = [
{name: 'Главная'},
{name: 'Каталог', //h1
children: [ //ul
{name: 'Компьютеры',//h1
children: [ //li -> ul
{name: 'Ноутбуки'}, //li h1
{name: 'Планшеты'} //li h1
]
}
]
},
{name: 'Профиль'}
];
const visualArray = arr => {
arr.forEach(item => {
for (let key in item) {
if (key == 'name') {
document.body.innerHTML += `<h1>${item.name}</h1>`;
};
if (key == 'children') {
const map = item[key].map(child => {
let res = '<ul>';
for (let key1 in child) {
if (key1 == 'name') {
res += `<h1>${child[key1]}</h1>`;
};
if (key1 == 'children') {
res += `<ul>
<li>${child[key1][0].name}</li>
<li>${child[key1][1].name}</li>
<ul>`
}
}
res += '</ul>';
return res;
})
document.body.innerHTML += map;
}
};
})
};
visualArray(navigation);