diff --git a/js-core/homeworks/homework-16/hw-16/index.html b/js-core/homeworks/homework-16/hw-16/index.html new file mode 100644 index 0000000..3bdba61 --- /dev/null +++ b/js-core/homeworks/homework-16/hw-16/index.html @@ -0,0 +1,11 @@ + + + + + Home work 16 + + + + + + \ No newline at end of file diff --git a/js-core/homeworks/homework-16/hw-16/src/main.js b/js-core/homeworks/homework-16/hw-16/src/main.js new file mode 100644 index 0000000..7609392 --- /dev/null +++ b/js-core/homeworks/homework-16/hw-16/src/main.js @@ -0,0 +1,163 @@ +/* + 0 Алгоритмы + Реализуйте функцию которая будет превращать трехмерный массив + в двухмерный, а если массив двухмерный, тогда в трехмерный массив + // solution([ [1, 'a'], [2, 'b'], [3, 'c'] ]) => [ [1, 2, 3], [a, b, c] ] + // solution([ [1, 3, 5], [2, 4, 6] ]) => [ [1, 2], [3, 4], [5, 6] ] + // solution([[]]) => [] + [ [ [ ] ] ] = [ [] ] + ИСПОЛЬЗУЙТЕ МЕТОДЫ МАССИВОВ ! + */ + +const solution = arr => { + if(arr.length === 2) { + let output = []; + + const firstPart = arr.reduce((newArr, childArr) => { + newArr.push(childArr[0]); + return newArr; + }, []); + + const secondPart = arr.reduce((newArr, childArr) => { + newArr.push(childArr[1]); + return newArr; + }, []); + + const thirdPart = arr.reduce((newArr, childArr) => { + newArr.push(childArr[2]); + return newArr; + }, []); + + output.push(firstPart); + output.push(secondPart); + output.push(thirdPart); + + return output; + } + + if(arr.length === 3) { + let output = []; + + const firstPart = arr.reduce((newArr, childArr) => { + newArr.push(childArr[0]); + return newArr; + }, []); + + const secondPart = arr.reduce((newArr, childArr) => { + newArr.push(childArr[1]); + return newArr; + }, []); + + output.push(firstPart); + output.push(secondPart); + + return output; + } +}; + +console.log(solution([[1, 3, 5], [2, 4, 6]])); +console.log(solution([[1, 'a'], [2, 'b'], [3, 'c']])); + +const navigation = [ + {name: 'Главная'}, + { + name: 'Каталог', + children: [ + { + name: 'Компьютеры', + children: [{name: 'Ноутбуки'}, {name: 'Планшеты'}] + } + ] + }, + {name: 'Профиль'} +]; + +/* + Визуализируйте массив, если в коллекции есть свойство + children, + тогда создайте вложенный лист + name - свойство h1 + children ul -> li + Используйте innerHTML + */ + +/* +

Main

+