Skip to content

Instantly share code, notes, and snippets.

@MartinMuzatko
Created October 9, 2019 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinMuzatko/b8150b99cebb31d8b222ac88a69999f7 to your computer and use it in GitHub Desktop.
Save MartinMuzatko/b8150b99cebb31d8b222ac88a69999f7 to your computer and use it in GitHub Desktop.
const chunk = (items, chunkSize) =>
[...Array(Math.round(items.length / chunkSize))]
.map((_, index) =>
items.slice(
index * chunkSize,
index * chunkSize + chunkSize))
// chunk([1,2,3,4,5], 2)
// [[1,2], [3,4], [5]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment