How to reshape an array with lodash

.zip.apply(, _.chunk("Your array", "columns"));
How this works:
Let's say you have an array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, etc]
_.chunk(array, 3) will give you [ [1,2,3], [4,5,6], [7,8,9], [10,11,12], [13, 14] ]
.zip.apply(, _.chunk(array, 3)); will give you: [ [1,4,7,10,13], [2,5,8,11,14], [3,6,9,12] ]

No comments:

This will make you a better decision maker | Annie Duke (author of “Thinking in Bets” and “Quit”, former pro poker…

Annie is a former professional poker player, decision-making expert, author, and special partner at First Round Capital.  ͏     ­͏     ­͏   ...

Contact Form

Name

Email *

Message *