Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
finished 2.6
  • Loading branch information
jshortz committed Jul 13, 2019
commit 9e8430236e7fca0425c797928dc2eb404cb729d3
22 changes: 17 additions & 5 deletions Week3/homework/step2-6.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
'use strict';

const arr2d = [[1, 2], [3, 4], [5, 6]];
const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
const arr3d = [ [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ] ];

function flattenArray2d(arr) {
// Replace this comment and the next line with your code
console.log(arr);
let newArray = [];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
newArray.push(arr[i][j]);
}
}
return newArray.sort();
}

function flattenArray3d(arr) {
// Replace this comment and the next line with your code
console.log(arr);
let arr3d = [];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
for (let k = 0; k < arr[i][j].length; k++) {
arr3d.push(arr[i][j][k]);
}
}
}
return arr3d;
}

console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6]
Expand Down