Skip to content

Instantly share code, notes, and snippets.

@EastSun5566
Created April 16, 2020 08:17
Show Gist options
  • Save EastSun5566/326aee7b4d30eaea3c66ae0c211019d7 to your computer and use it in GitHub Desktop.
Save EastSun5566/326aee7b4d30eaea3c66ae0c211019d7 to your computer and use it in GitHub Desktop.
Creates an array of elements split into groups the length of size.
const chunk = (input, size) => input.reduce((arr, item, index) => index % size === 0
? [...arr, [item]]
: [...arr.slice(0, -1), [...arr.slice(-1)[0], item]], []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment