Create function using => syntax, `averagePrice` that takes in an array of item objects, and returns the
Question:
Create function using => syntax, `averagePrice` that takes in an array of item
objects, and returns the average cost of all items rounded to the nearest cent with
a dollar sign in front. If no price is given for an item, the cost is one dollar.
Hint: Look up `toFixed()` on MDN
Examples:
const items1 = [
{item: "baseball", cost: 3.32, color: "white"},
{item: "cup", cost: 2.50, size: "medium"},
{item: "perfume", cost: 4.75, scent: "vanilla"},
{item: "paint", cost: 6.00, color: "brown"}
];
const items2 = [
{item: "hotdog", cost: 2.75},
{item: "tater tots", size: "small"}, // Default $1
{item: "soda", flavor: "coke"} // Default $1
]
averagePrice(items1) // '$4.14'
averagePrice(items2) // '$1.58'
***********************************************************************/
const averagePrice = (arr) => {
// Your code here
}
/**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/
try {
module.exports = averagePrice;
} catch(e) {
module.exports = null;
}