we want you to write a function, organizeitems, that organizes items by category. the argument to the function is an array of item objects. each item object has 3 properties, category (string), itemname (string), and onsale (boolean). here's an example:

Answer :

A function, organize items, that organizes items by category.

The Function

const itemData =

 [ { category: 'fruit',  itemName: 'apple', onSale: false }

 , { category: 'canned', itemName: 'beans', onSale: false }

 , { category: 'canned', itemName: 'corn',  onSale: true  }

 , { category: 'frozen', itemName: 'pizza', onSale: false }

 , { category: 'fruit',  itemName: 'melon', onSale: true  }

 , { category: 'canned', itemName: 'soup',  onSale: false }

 ]

const result = itemData.reduce((r,{category,itemName,onSale})=>

 {

 r[category] = r[category] || []

 r[category].push( itemName + (onSale?'($)':''))

 return r

 },{})

// show result

console.log( JSON.stringify(result)

                .replace(`{"`,`\nresult =\n  { `)

                .replace(/"],"/g,`' ]\n  , `)

                .replace(`"]}`,`' ]\n  }`)

                .replace(/":\["/g,`: [ '`)

                .replace(/","/g,`', '`))

Read more about programming here:

https://brainly.com/question/23275071

#SPJ1

Other Questions