Created
November 28, 2018 14:43
-
-
Save KevinPy/54cb183c8b72e73887e094007941ee4a to your computer and use it in GitHub Desktop.
Transform Array of Array => Horizontal to Vertical
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 arr = [ | |
[1, 2, 3], | |
[4, 5, 6], | |
[7, 8, 9] | |
]; | |
const rotate = arr.reduce((value, row) => { | |
return row.map((_, i) => { | |
return [...(value[i] || []), row[i]]; | |
}); | |
}, []); | |
console.log(rotate); | |
/* | |
[ | |
[1, 4, 7], | |
[2, 5, 8], | |
[3, 6, 9] | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment