I have a javascript object, and array of id's:
var ids = [46,44,49,47];
var obj = {
"46": {
"group": "A",
"temp": 26,
"humid": 36
},
"44": {
"group": "B",
"temp": 19,
"humid": 32
},
"49": {
"group": "B",
"temp": 20,
"humid": 31
},
"47": {
"group": "A",
"temp": 24,
"humid": 32
}
};
I want to get the average 'temp' of each 'group'. How can I do this?
I found other examples that would solve this problem, however, these examples assume that 'group' will always be the same. In my case, 'group' is always changing.
So essentially I need to find how many unique groups exist, then return the average 'temp' value of each.
I attempted to use some for loops nested together, but it got complicated quickly...
Expected Output:
avgTemps = {"A":25, "B": 19.5}
idvalues repeated inids? Seems like useless duplication. You can get the keys from an object withObject.keys.idselements do not exist as a key inobj, and / or, someobjkeys do not exist in theidsarray?