Suppose we start with this original array of objects:
{vendor:"vendor1", item:"item1", price:1100, rank:0},
{vendor:"vendor1", item:"item2",price:3200, rank:0},
{vendor:"vendor1", item:"item3", price:1100, rank:0},
{vendor:"vendor2", item:"item1", price:2000, rank:0},
{vendor:"vendor2", item:"item2",price:2000, rank:0},
{vendor:"vendor2", item:"item3", price:3200, rank:0},
{vendor:"vendor3", item:"item1", price:3200, rank:0},
{vendor:"vendor3", item:"item2",price:1100, rank:0},
{vendor:"vendor3", item:"item3", price:2000, rank:0},
How can we assign ranks based on the price property within each item category in comparison to all vendors offering the same item?
Desired Output:
{vendor:"vendor1", item:"item1", price:1100, rank:1},
{vendor:"vendor1", item:"item2",price:3200, rank:3},
{vendor:"vendor1", item:"item3", price:1100, rank:1},
{vendor:"vendor2", item:"item1", price:2000, rank:2},
{vendor:"vendor2", item:"item2",price:2000, rank:2},
{vendor:"vendor2", item:"item3", price:3200, rank:3},
{vendor:"vendor3", item:"item1", price:3200, rank:3},
{vendor:"vendor3", item:"item2",price:1100, rank:1},
{vendor:"vendor3", item:"item3", price:2000, rank:2},