Skip to content

Commit

Permalink
laba 4 yeeeeah lmao
Browse files Browse the repository at this point in the history
  • Loading branch information
pahan committed Mar 20, 2022
1 parent 204c2ca commit 90cdbb5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lab4/4.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
*/

function get1DArray(arr) {
return arr.flat(Infinity);
for (let i = 0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
get1DArray(arr[i]);
for (let j = 0; j < arr[i].length; j++) {
arr.splice(i, 0, arr[i][j]);
i++;
}
arr.splice(i, 1);
i--;
}
}
return arr;
}

module.exports = get1DArray;
console.log(get1DArray([1, 2, 'aa', [1, 2, 3],
[
[1, 2],
[1, 2]
],
[
[
[1, 2, [1, 2, [2]]], 3
], 4
]
]));
//console.log(get1DArray([[[1,2]]]));
console.log(get1DArray([1, 2, 'aa', [1, 2, 3], [ [1, 2], [1, 2] ], [ [ [1, 2, [1, 2, [2]]], 3], 4]]));

0 comments on commit 90cdbb5

Please sign in to comment.