Created
February 24, 2020 07:25
-
-
Save inlife/f61f70e717ac6a5172d074d039d3d689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array2d = array1d | |
.reduce((cur, i) => { | |
/* transform 1d array to 2d */ | |
let lastInd = cur.length-1 | |
let lastVal = cur[lastInd] | |
if (lastVal.length === 3) { | |
return cur.concat([[i]]) | |
} | |
return cur | |
.slice(0, lastInd) | |
.concat([lastVal.concat(i)]) | |
}, [[]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment