I have really searched and cannot find the right answer. I have an array of objects:
[ { currentMonth: 'September-2018',
employeeNumber: '130',
caLastName: 'Bartoletti',
caFirstName: 'Elias',
payrollCode: '505',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 24,
wages: 633.6 },
{ currentMonth: 'September-2018',
employeeNumber: '130',
caLastName: 'Bartoletti',
caFirstName: 'Elias',
payrollCode: '404',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 48,
wages: 2534.4 },
{ currentMonth: 'September-2018',
employeeNumber: '130',
caLastName: 'Bartoletti',
caFirstName: 'Elias',
payrollCode: '303',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 24,
wages: 633.6 },
{ currentMonth: 'September-2018',
employeeNumber: '130',
caLastName: 'Bartoletti',
caFirstName: 'Elias',
payrollCode: '203',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 24,
wages: 950.4000000000001 },
{ currentMonth: 'September-2018',
employeeNumber: '130',
caLastName: 'Bartoletti',
caFirstName: 'Elias',
payrollCode: '202',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 48,
wages: 2534.4 },
{ currentMonth: 'September-2018',
employeeNumber: '196',
caLastName: 'Barrows',
caFirstName: 'Felicia',
payrollCode: '500',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 24,
wages: 576 },
{ currentMonth: 'September-2018',
employeeNumber: '196',
caLastName: 'Barrows',
caFirstName: 'Felicia',
payrollCode: '400',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 48,
wages: 2304 },
{ currentMonth: 'September-2018',
employeeNumber: '196',
caLastName: 'Barrows',
caFirstName: 'Felicia',
payrollCode: '300',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 24,
wages: 576 },
{ currentMonth: 'September-2018',
employeeNumber: '196',
caLastName: 'Barrows',
caFirstName: 'Felicia',
payrollCode: '201',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 24,
wages: 864 },
{ currentMonth: 'September-2018',
employeeNumber: '196',
caLastName: 'Barrows',
caFirstName: 'Felicia',
payrollCode: '200',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 48,
wages: 2304 } ]
All I want is a new array of objects showing currentMonth, employeeNumber, caLastName, caFirstName, rate_per_hour, clientType, the sum of totalHours and the sum of wages for each employee. So in this example, an array with just two objects.
I have tried reduce and filter but I cannot fathom exactly where I am going wrong. I would rather not do a loop as I suspect that would be a lot less efficient.
The new array would look a bit like:
[ { currentMonth: 'September-2018',
employeeNumber: '130',
caLastName: 'Bartoletti',
caFirstName: 'Elias',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 168,
wages: 7286.4 },
{ currentMonth: 'September-2018',
employeeNumber: '196',
caLastName: 'Barrows',
caFirstName: 'Felicia',
rate_per_hour: 25,
clientType: 'Single',
totalHours: 168,
wages: 6624 } ]