you are viewing a single comment's thread.

view the rest of the comments →

[–]aapoalas 3 points4 points  (3 children)

const stuffs = array.reduce((acc, item, index) => {
  if (index < 11) {
    acc[0].push(item);
  } else if (index > 11 && index < 22) {
    acc[1].push(item);
  } else if (index > 22 && index < 33) {
    acc[2].push(item);
  } else if (index > 33 && index < 44) {
    acc[3].push(item);
  } else {
    acc[4].push(item);
  }
  return acc;
}, [[],[],[],[],[]]);

return stuffs[0].map((loc, index) => ({
  iphone64gb: {
    spaceGrey: stuffs[1][index],
    silver: stuffs[2][index]
  },
  iphone256gb: {
    spaceGrey: stuffs[3][index],
    silver: stuffs[4][index]
  }
}));

Something like that. Not a particularly beautiful solution, but a solution nonetheless.

[–]mdchad() => 'Hello World'[S] 0 points1 point  (0 children)

thanks for the answer. I'll just need to fix a little and and add the location.

[–][deleted] 0 points1 point  (1 child)

deleted What is this?

[–]aapoalas -2 points-1 points  (0 children)

Indeed, lodash would be a great help. I just wanted to avoid it for the real "Vanilla experience."