If I have this array:
const purchases = [
{item: 'shoes', cost: 9, buyer: 'sheryl'},
{item: 'candy', cost: 2, buyer: 'steve'},
{item: 'candy', cost: 2, buyer: 'joe'},
{item: 'apple', cost: 1, buyer: 'mary'},
{item: 'candy', cost: 2, buyer: 'jeff'},
{item: 'shoes', cost: 9, buyer: 'john'}];
I want to find the Item that sells the most, and how many were bought returned in an object like this:
{item: 'candy', sales: 3}
if there are ties, just return one of them.
This is the most simple way I can put it. I have found many questions similar to this but none that had a solution to this exactly. Can someone please help?