I have an array:
var arr = [
{price: 5, amount: 100},
{price: 3, amount: 50},
{price: 10, amount: 20},
{price: 3, amount: 75},
{price: 7, amount: 1
Use reduce
to convert it an object first to remove the duplicates and last duplicate should override the previous one
var obj = arr.reduce( ( acc, c ) => Object.assign(acc, {[c.price]:c.amount}) , {});
Convert it back to array and sort the same
var output = Object.keys( obj )
.map( s => ({ price : s, amount : obj[ s ] }) )
.sort( ( a, b ) => b.price - a.price );
Demo
var arr = [
{price: 5, amount: 100},
{price: 3, amount: 50},
{price: 10, amount: 20},
{price: 3, amount: 75},
{price: 7, amount: 15},
{price: 3, amount: 65},
{price: 2, amount: 34}
];
var obj = arr.reduce( ( acc, c ) => Object.assign(acc, {[c.price]:c.amount}) , {});
var output = Object.keys( obj )
.map( s => ({ price : s, amount : obj[ s ] }) )
.sort( ( a, b ) => b.price - a.price );
console.log( output );