Created
September 4, 2014 07:24
-
-
Save lambdaX/9bb87f5b1ea9c9ff01bd to your computer and use it in GitHub Desktop.
My way to chunk an Array
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
Array.prototype.chunk = function (n) { | |
return this.reduce(function (g,v,i) { | |
var chunk = (i-i%n) / n; | |
if (!(i%n)) g[chunk] = []; | |
g[chunk].push(v); | |
return g; | |
},[]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment