Skip to content

Instantly share code, notes, and snippets.

@tuxsudo
Created December 15, 2015 16:30
Show Gist options
  • Save tuxsudo/0738644567a4eb11df95 to your computer and use it in GitHub Desktop.
Save tuxsudo/0738644567a4eb11df95 to your computer and use it in GitHub Desktop.
Split an array into N number of chunks
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