(inventory)
| 1 | function inventoryByCategory (inventory) { |
| 2 | return inventory.reduce((acc, next) => { |
| 3 | const categories = next.categories |
| 4 | categories.forEach(c => { |
| 5 | if (acc[c]) { |
| 6 | acc[c].items.push(next) |
| 7 | } else { |
| 8 | acc[c] = {} |
| 9 | acc[c].items = [] |
| 10 | acc[c].items.push(next) |
| 11 | } |
| 12 | }) |
| 13 | return acc |
| 14 | }, {}) |
| 15 | } |
| 16 | |
| 17 | export { |
| 18 | inventoryByCategory |
no outgoing calls
no test coverage detected