Test case details

Preparation Code

const nums = new Array(100).fill(0).map(() => new Array(100).fill(0));

Test cases

Test #1

const bad1a = nums.reduce((acc, row) => [...acc, ...row], []);

Test #2

const bad1b = nums.reduce((acc, row) => { row.forEach(el => acc.push(el)); return acc; }, []);

Test #3

const bad1c = nums.reduce((acc, row) => { acc.push(...row); return acc; }, []);

Test #4

let bad2a = []; nums.forEach((arr) => bad2a = bad2a.concat(arr));

Test #5

let bad2b = []; for (let row = 0; row < nums.length; row++) { bad2b = bad2b.concat(nums[row]); }

Test #6

const bad3 = JSON.parse("[" + JSON.stringify(nums).replace(/\[|\]/g, "") + "]");

Test #7

const good1a = nums.flat();

Test #8

const good1b = nums.flatMap(row => row);

Test #9

const good2a = []; nums.forEach((arr) => good2a.push(...arr));

Test #10

const good2b = []; for (let row = 0; row < nums.length; row++) { good2b.push(...nums[row]); }

Test #11

const good3a = []; for (let row = 0; row < nums.length; row++) { for (let col = 0; col < nums[0].length; col++) { good3a.push(nums[row][col]); } }

Test #12

const good3b = new Array(nums.length * nums[0].length); let ind = 0; for (let row = 0; row < nums.length; row++) { for (let col = 0; col < nums[0].length; col++) { good3b[ind] = nums[row][col]; ind++ } }

Test #13

const good4a = [].concat.apply([], nums);

Test #14

const good4b = [].concat(...nums);

Test #15

const good4c = Array.prototype.concat.call([], ...nums);

Test #16

const good5 = []; nums.forEach(row => Array.prototype.push.apply(good5, row));