I've scoured through many posts and have been working on this problem for too long. The gist is that I want to filter an array if there are duplicate object id's and return the object with the lower value or "val", otherwise return the original element.
Start with:
**edited input for clarification
let input = [
{"id": 1, "val": 3},
{"id": 2, "val": 1},
{"id": 3, "val": 4},
{"id": 1, "val": 0}
]
function removeDuplicates(array, propertyName) {
// where propertyName is "id"
}
The result of the function should be:
[
{"id": 1, "val": 0},
{"id": 2, "val": 1},
{"id": 3, "val": 4}
]
valalways0? or it's not important in duplication?