Skip to content

Instantly share code, notes, and snippets.

@jalada
Created April 8, 2019 11:40
Show Gist options
  • Save jalada/59e21719ab2684cfba88b42ab4e98c20 to your computer and use it in GitHub Desktop.
Save jalada/59e21719ab2684cfba88b42ab4e98c20 to your computer and use it in GitHub Desktop.
Reverse chunk
const chunk = function(array, size) {
var length = array.length;
var index = length,
result = Array(Math.ceil(length / size)),
resIndex = result.length-1;
var start;
while (index > 0) {
start = Math.max(0, index - size);
result[resIndex--] = array.slice(start, index);
index = start;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment