Skip to content

Instantly share code, notes, and snippets.

@paitonic
Created August 24, 2019 04:49
Show Gist options
  • Save paitonic/3884099d9ffaf9341038a35ea88d38b1 to your computer and use it in GitHub Desktop.
Save paitonic/3884099d9ffaf9341038a35ea88d38b1 to your computer and use it in GitHub Desktop.
chunk
function chunk(array, size) {
function partition(array, start, result=[]) {
if (array.length === 0) {
return result;
}
return partition(array.slice(start+size, array.length), start+size, [...result, array.slice(0, size)])
}
return partition(array, 0);
}
chunk([1, 2, 3, 4, 5], 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment