Skip to content

Instantly share code, notes, and snippets.

@srttk
Created April 7, 2017 02:54
Show Gist options
  • Save srttk/01af05114c950b784cfc1073302a86eb to your computer and use it in GitHub Desktop.
Save srttk/01af05114c950b784cfc1073302a86eb to your computer and use it in GitHub Desktop.
Array chunk function
/*
chunk array elements
*/
function chunckArray(arr,chunkSize) {
return arr.map( function(e,i){
return i%chunkSize===0 ? arr.slice(i,i+chunkSize) : null;
})
.filter(function(e){ return e; });
}
console.log('Array chunk')
var chunk_size = 5;
var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17];
var arrayChunked = chunckArray(arr,4)
console.log(arrayChunked)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment