diff --git a/homework-16/index.html b/homework-16/index.html new file mode 100644 index 0000000..04dc733 --- /dev/null +++ b/homework-16/index.html @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/homework-16/js.js b/homework-16/js.js new file mode 100644 index 0000000..78756cf --- /dev/null +++ b/homework-16/js.js @@ -0,0 +1,197 @@ +/* + 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 flatten = arr => { + return arr.reduce((newArr, value, index, arr) => { + return Array.isArray(value) ? + newArr.concat(flatten(value)) : + newArr.concat(value) + }, []) +}; + +const solution = array => { + let arr = flatten(array) + + if (array.length == 2) { + let firstArr = [] + let secondArr = [] + let therdArr = [] + let resultArr = [] + arr.forEach((value, index, arr) => { + if (arr[index] == 1 || arr[index] == 2) { + firstArr.push(value) + } + if (arr[index] == 3 || arr[index] == 4) { + secondArr.push(value) + } + if (arr[index] == 5 || arr[index] == 6) { + therdArr.push(value) + } + }) + resultArr.push(firstArr, secondArr, therdArr) + console.log(resultArr); + } + if (array.length == 3) { + let stringArr = [] + let numbArr = [] + let resultArr = [] + arr.forEach((value, index, arr) => { + if (typeof value == 'number') { + numbArr.push(value) + } + if (typeof value == 'string') { + stringArr.push(value) + } + }) + resultArr.push(numbArr, stringArr) + console.log(resultArr); + } + if (array.length == 0) { + console.log(arr); + } + +}; + +solution([ + [1, 3, [5]], + [2, 4, 6] +]); +solution([ + [1, 'a'], + [2, 'b'], + [3, 'c'] +]); +solution([ + [ + [] + ] +]) + + + + + + + + + +const navigation = [ + {name: 'Главная'}, + { + name: 'Каталог', + children: [ + { + name: 'Компьютеры', + children: [{name: 'Ноутбуки'}, {name: 'Планшеты'}] + } + ] + }, + {name: 'Профиль'} +]; +/* + Визуализируйте массив, если в коллекции есть свойство + children, + тогда создайте вложенный лист + name - свойство h1 + children ul -> li + Используйте innerHTML +

Main

+