Skip to content

Instantly share code, notes, and snippets.

@Ai01
Created August 23, 2017 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ai01/6bd0ca736dd4d424e9528e2b92084d3e to your computer and use it in GitHub Desktop.
Save Ai01/6bd0ca736dd4d424e9528e2b92084d3e to your computer and use it in GitHub Desktop.
const arr = {
children: [1,2,3]
};
arr.childrenGroup = [];
arr.children.reduce((r, e, index) => {
const lenghtOfChildren = qcSort.children.length;
if (index % 2 === 1) {
arr.childrenGroup.push([r,e]);
} else if (lenghtOfChildren % 2 === 1 && index === lenghtOfChildren - 1) {
arr.childrenGroup.push([e]);
}
return e;
}, null);
console.log(arr.childrenGroup);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment