I have an array like this:
var array = [
{"id":"A","type":"blue","rng":"50"},
{"id":"A","type":"blue","rng":"75"},
{"id":"A","type":"grey","rng":"76"},
{"id":"B","type":"blue","rng":"50"},
{"id":"B","type":"grey","rng":"85"},
{"id":"B","type":"grey","rng":"86"},
{"id":"C","type":"blue","rng":"50"},
{"id":"C","type":"grey","rng":"65"}
]
Note: Objects arranged in random order.
I need away to filter out the duplicate "id":"*","type":"blue" and "id":"*","type":"grey" with the higher "rng".
So the final result is:
var result = [
{"id":"A","type":"blue","rng":"50"},
{"id":"A","type":"grey","rng":"76"},
{"id":"B","type":"blue","rng":"50"},
{"id":"B","type":"grey","rng":"86"},
{"id":"C","type":"blue","rng":"50"},
{"id":"C","type":"grey","rng":"65"}
]
I'm keen on using underscore but any other solution is welcome too.