DEV Community

Unrolling Matrix Walkthrough - JS

Kim Heidorn on August 09, 2019

As I’ve been starting my job search, I have been grinding LeetCode problems, tackling all the algorithm practice I can to ease my nerves going into...
Collapse
 
fc250152 profile image
Nando

Hi Kim, I've appreciated your exercise!
Anyway, because I love short writing I prefer to use functional methods and ES6.
Try this, for example:

const arr = [[1, 2, 3, 4], [5,6,7,8], [9,10,11,12], [13,14,15,16]];
console.log(arr);
console.log(arr.reduce((prev,curr,idx,[]) => [...prev,...curr]).toString());

Have a nice week end!