even-chunks

Split an array evenly into chunks

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
even-chunks
401.1.06 years ago7 years agoMinified + gzip package size for even-chunks in KB

Readme

even-chunks
NPM Version NPM Downloads Build Status Coverage Status Dependency Status
Split an array evenly into chunks.
Install: npm install even-chunks
const evenChunks = require('even-chunks');

evenChunks([1,2,3,4,5,6,7], 2) // => [ [ 1, 2, 3, 4 ], [ 5, 6, 7 ] ]
evenChunks([1,2,3,4,5,6,7], 3) // => [ [ 1, 2 ], [ 3, 4, 5 ], [ 6, 7 ] ]
evenChunks([1,2,3,4,5,6,7], 4) // => [ [ 1, 2 ], [ 3, 4 ], [ 5 ], [ 6, 7 ] ]

evenChunks([1,2,3,4,5,6,7], 3, evenChunks.ROUND_ROBIN)
  // => [ [ 1, 4, 7 ], [ 2, 5 ], [ 3, 6 ] ]

evenChunks([1,2,3,4,5,6,7,8,9,10], 4, evenChunks.PRIORITIZE_FIRST)
  // => [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ], [ 9, 10 ] ]

evenChunks([1,2,3,4,5,6,7,8,9,10], 4, evenChunks.PRIORITIZE_CENTER)
  // => [ [ 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ], [ 9, 10 ] ]

evenChunks([1,2,3,4,5,6,7,8,9,10], 4, evenChunks.PRIORITIZE_LAST)
  // => [ [ 1, 2 ], [ 3, 4 ], [ 5, 6, 7 ], [ 8, 9, 10 ] ]
License
MIT