I am stuck a little on how to correctly make an array based on 2 other arrays.
I have one array like this:
let date = [1522303200000, 1522389600000, 1522476000000]
and the second array looks somewhat like this:
let people = [
{
"id": 0,
"name": "Sophia Mason",
"biography": "Lorem ...",
"availability": [
{
"date": 1522303200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522389600000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522476000000,
"times": ["10:00 am", "2:30 pm", "5:00 pm"]
},
{
"date": 1522735200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
}
]
},
{
"id": 1,
"name": "Brandon Hampton",
"biography": "Lorem ...",
"availability": [
{
"date": 1522303200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522476000000,
"times": ["10:00 am", "2:30 pm", "5:00 pm"]
},
{
"date": 1522648800000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522735200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
}
]
}
]
I am trying to create an array that has the date as the top level of each index in the array and then each corresponding person in each day if there is availability for that date. I am thinking something similar to this:
let calendar = [
[
1522303200000,
"photographers": [
{
"id": 0,
"name": "Sophia Mason",
"biography": "Lorem ...",
"availability": [
{
"date": 1522303200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522389600000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522476000000,
"times": ["10:00 am", "2:30 pm", "5:00 pm"]
},
{
"date": 1522735200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
}
]
},
{
"id": 1,
"name": "Brandon Hampton",
"biography": "Lorem ...",
"availability": [
{
"date": 1522303200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522476000000,
"times": ["10:00 am", "2:30 pm", "5:00 pm"]
},
{
"date": 1522648800000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522735200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
}
]
}
]
],
[
1522303200000,
"photographers": [
{
"id": 0,
"name": "Sophia Mason",
"biography": "Lorem ...",
"availability": [
{
"date": 1522303200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522389600000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
},
{
"date": 1522476000000,
"times": ["10:00 am", "2:30 pm", "5:00 pm"]
},
{
"date": 1522735200000,
"times": ["9:00 am", "2:30 pm", "5:00 pm", "6:00 pm"]
}
]
}
]
],
...
]
But I am stuck on how to go about this currently. I have probably been looking at this for too long to really wrap my head around this.
I have looked at the following places to get some ideas:
Any help would be appreciated!