Created
December 15, 2015 16:30
-
-
Save tuxsudo/0738644567a4eb11df95 to your computer and use it in GitHub Desktop.
Split an array into N number of chunks
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
| export default ( chunkLength = 20 , sourceArray = [] ) => ( | |
| sourceArray.reduce( (accumulated, current, index) => { | |
| let chunkN = Math.floor( index/chunkLength ); | |
| accumulated[ chunkN ] = ( accumulated[ chunkN ]||[]).concat( current ); | |
| return accumulated; | |
| }, []) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment