Last active
August 20, 2018 20:46
-
-
Save 0xch4z/92475d4061e937c9d6cc2bf9857ceb39 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // chunk array reduces the array to a set of chunks of size n | |
| const chunkArray = (a = [], n = 2) => | |
| a.reduce((acc, el, idx) => { | |
| const chunk = Math.floor(idx / n); | |
| if (!Array.isArray(acc[chunk])) acc[chunk] = []; | |
| acc[chunk].push(el); | |
| return acc; | |
| }, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment