MCPcopy Index your code
hub / github.com/jamstack-cms/jamstack-ecommerce / inventoryByCategory

Function inventoryByCategory

utils/inventoryByCategory.js:1–15  ·  view source on GitHub ↗
(inventory)

Source from the content-addressed store, hash-verified

1function 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
17export {
18 inventoryByCategory

Callers 1

inventoryForCategoryFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected