Created
April 7, 2017 02:54
-
-
Save srttk/01af05114c950b784cfc1073302a86eb to your computer and use it in GitHub Desktop.
Array chunk function
This file contains 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 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