Skip to content

Instantly share code, notes, and snippets.

@larryyangsen
Last active May 15, 2018 08:07
Show Gist options
  • Save larryyangsen/8ec3b679ecd752029aa603d424b2bd88 to your computer and use it in GitHub Desktop.
Save larryyangsen/8ec3b679ecd752029aa603d424b2bd88 to your computer and use it in GitHub Desktop.
group array
const group = (arr = [], length = 2) => {
if (length > arr.length) return;
const newArr = arr.slice();
const returnArr = [];
while (newArr.length > length) {
const values = newArr.splice(0, length);
returnArr.push(values);
}
returnArr.push(newArr);
return returnArr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment