You are given an array of shopping order records. Each record looks like:
[ { user: 8, total: 50, items: ['notebook'] }, { user: 7, total: 150, items: ['pen'] }, { user: 1, total: 10, items: ['eraser'] }, { user: 7, total: 100, items: ['stapler', 'marker'] }, { user: 7, total: 200, items: ['notebook'] }, { user: 2, total: 200, items: ['pencil'] }, { user: 2, total: 200, items: ['marker'] }, ]
Each order has:
user: User ID of the ordertotal: Total cost of the orderitems: Array of purchased items (alphabetical order)Your task: Implement mergeOrders(orders) to merge orders by user:
Example
mergeOrders(orders); // [ // { user: 8, total: 50, items: ['notebook'] }, // { user: 7, total: 450, items: ['marker', 'notebook', 'pen', 'stapler'] }, // { user: 1, total: 10, items: ['eraser'] }, // { user: 2, total: 400, items: ['marker', 'pencil'] }, // ]
JavaScript Function
No test results yet
Click "Run" to execute tests