I have 5 arrays:
let people = [
'Alica Brereton',
'David Ernest',
'David Ernest',
'Gabriella Hyde',
'Gabriella Hyde',
'Joel Forro',
'Joel Forro',
'William Kotai'
]
let keys = [ 'product', 'cost per unit', 'units', 'Total Price' ]
let drugs = ['Marijuana',
'Methamphetamine',
'cocaine',
'Marijuana',
'Methamphetamine',
'ecstasy',
'heroin',
'ecstasy'
]
let unitPrice = [
'9.18', '108.78',
'80', '9.18',
'108.78', '19.12',
'91.16', '19.12'
]
let amount = ['50', '5', '2',
'10', '8', '10',
'5', '20'
]
How can I convert the arrays to an object of object literals resembling something like this:
{
'Alica Brereton':[
{
product:'Marijuana',
unitPrice:'9.18',
units:'50',
totalPrice:'459.00'
}
],
'William Kotai':[
{
product:'ecstasy',
unitPrice:'19.12',
units:'20',
totalPrice:'382.40'
}
],
'Joel Forro':[
{
product:'heroin',
unitPrice:'91.16',
units:'5',
totalPrice:'455.80'
},
{
product:'ecstasy',
unitPrice:'19.12',
units:'10',
totalPrice:'191.20'
}
],
'David Ernest':[
{
product:'Methamphetamine',
unitPrice:'108.78',
units:'5',
totalPrice:'543.90'
},
{
product:'cocaine',
unitPrice:'80',
units:'2',
totalPrice:'160.00'
}
],
'Gabriella Hyde':[
{
product:'Marijuana',
unitPrice:'9.18',
units:'10',
totalPrice:'91.80'
},
{
product:'Methamphetamine',
unitPrice:'108.78',
units:'8',
totalPrice:'870.24'
}
]
}
I understand i still need to total total price which is a simple multiplication and that there are some duplicates of people who have two orders that need to be corrected also but just looking for some help to move in the right direction