I would like to combine the quantity values of objects if ohmage, tolerance, and wattage values are the same as previous checked objects. Starting object:
var x = [{
    date: "2020",
    ohmage: "1k45",
    quantity: 5000,
    tolerance: 5,
    wattage: 2
}, {
    date: "2020",
    ohmage: "9k34",
    quantity: 1000,
    tolerance: 2,
    wattage: 0.125
}, {
    date: "2020",
    ohmage: "1k45",
    quantity: 3000,
    tolerance: 2,
    wattage: 2
}, {
    date: "2020",
    ohmage: "1k45",
    quantity: 3500,
    tolerance: 5,
    wattage: 2
}, {
    date: "2020",
    ohmage: "1k45",
    quantity: 500,
    tolerance: 5,
    wattage: 0.5
}];
Desired object:
var x = [{
    date: "2020",
    ohmage: "1k45",
    quantity: 8500,
    tolerance: 5,
    wattage: 2
}, {
    date: "2020",
    ohmage: "9k34",
    quantity: 1000,
    tolerance: 2,
    wattage: 0.125
}, {
    date: "2020",
    ohmage: "1k45",
    quantity: 3000,
    tolerance: 2,
    wattage: 2
}, {
    date: "2020",
    ohmage: "1k45",
    quantity: 500,
    tolerance: 5,
    wattage: 0.5
}];
I took a look at Merge duplicate objects in array of objects and redid the function but it doesn't combine all objects which should be combined. My current function:
var seen = {};
array = array.filter(entry => {
    var previous;
    // Have we seen this ohmage before?
    if (seen.hasOwnProperty(entry.ohmage)) {
        if (entry.tolerance == seen[entry.ohmage].tolerance && entry.wattage == seen[entry.ohmage].wattage) {
            console.log(true)
            // Yes, grab it and add this quantity to it
            previous = seen[entry.ohmage];
            previous.quantity.push(entry.quantity);
            // Don't keep this entry, we've merged it into the previous one
            return false;
        }
    }
    // entry.quantity probably isn't an array; make it one for consistency
    if (!Array.isArray(entry.quantity)) {
        entry.quantity = [entry.quantity];
    }
    // Remember that we've seen it
    seen[entry.ohmage] = entry;
    // Keep this one, we'll merge any others that match into it
    return true;
});
 
    