I have an array of objects and two of the objects in the array are the same (last two):
[
{
"facilities": 1,
"place": "Campbellsville",
"state": "KY",
"lat": 37.34595018,
"lon": -85.34544564
},
{
"facilities": 1,
"place": "Lexington",
"state": "KY",
"lat": 38.040584,
"lon": -84.503716
},
{
"facilities": 1,
"place": "Hebron",
"state": "KY",
"lat": 39.066147,
"lon": -84.703189
},
{
"facilities": 1,
"place": "Hebron",
"state": "KY",
"lat": 39.066147,
"lon": -84.703189
}
]
I want to combine the two objects that are the same into a single object with the 'facilities' key to be a sum of each of the 'facilities' values:
[
{
"facilities": 2,
"place": "Campbellsville",
"state": "KY",
"lat": 37.34595018,
"lon": -85.34544564
},
{
"facilities": 1,
"place": "Lexington",
"state": "KY",
"lat": 38.040584,
"lon": -84.503716
},
{
"facilities": 2,
"place": "Hebron",
"state": "KY",
"lat": 39.066147,
"lon": -84.703189
},
]
Is there a way to do this in javascript or using Node's underscore.js?