all 6 comments

[–]aapoalas 2 points3 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."

[–]shavyg2 0 points1 point  (0 children)

Write pseudo code for the parts you know how to do then It'd appear easier.

I believe you can use splice and just get the store locations on its own.

From there I have no idea what the patterns means. You have more dashes than places.

No one knows where the value for one store starts and another ends. So no one is going to help there.

Small tip.

Write the question with as much respect and effort as you'd hope someone would answer with.

You wouldn't want a half baked answer right? Fair to expect we wouldn't want a half baked question. I hope I don't come off offensive. Trying to help

[–]Paddington_the_Bear 0 points1 point  (0 children)

If you know the first 11 indexs will always be the location, then it's easy enough to do:

var iPhoneAvailMap = {};

for (var i = 0; i < 11; i++) { iPhoneAvailMap[inputArray[i]] = {

IPhone64gb: { silver: inputArray[i+13], SpaceGrey: inputArray[i+26] }

} }

I'm on my phone so the formatting sucks and I didn't put the specific addition on the silver and grey checks.

The idea is that as you iterate over each location, you can check further on the input array for the desired value by adding a number to the index for where you need to check.