I am beginner in data structure and trying to improve my skills. I am trying to divide the object value to list of other object. So I/P is
1st Object JSON:
let mapMonth ={
"10": 8,
"11": 30,
"12": 31,
"01": 23
}
where 10 is Oct, 11 is Nov, 12 is Dec and 01 is Jan.
2nd Object JSON:
let mapData = {
"key1": {
"subkey1": [
[407341537, 1666737463, 363248139, 596560162]
],
"subkey2": ["Oct", "Nov", "Dec", "Jan"]
},
"key2": {
"subkey1": [
[78491802, 334718068, 68299710, 81365082]
],
"subkey2": ["Oct", "Nov", "Dec", "Jan"]
},
"key3": {
"subkey1": [
[501844, 3362217, 648527, 1073573]
],
"subkey2": ["Oct", "Nov", "Dec", "Jan"]
}
}
So now I need to divide 407341537 with 8 i.e 50917692.125, 1666737463 with 30 i.e 55557915.4333 and so on.. Expected output:
{
"key1": {
"subkey1": [
[50917692.125, 55557915.4333, 11717681.9,72466846.2174]
],
"subkey2": ["Oct", "Nov", "Dec", "Jan"]
},
"key2": {
"subkey1": [
[9811475.25, 11157268.9333, 2203216.45161, 3537612.26087]
],
"subkey2": ["Oct", "Nov", "Dec", "Jan"]
},
"key3": {
"subkey1": [
[62730.5, 112073.9, 20920.225, 46677.086]
],
"subkey2": ["Oct", "Nov", "Dec", "Jan"]
}
}
Code I have tried:
let averageObj = {};
var count = 0;
for (let key in mapData) {
averageObj[key] = [];
mapData[key]['subkey1'][0].forEach((data, index) => {
for (let monthKey in mapMonth) {
averageObj[key].push(data / mapMonth[monthKey]);
}
});
}
Please let me know if you need anything else.
mapMonth["10"]value should be used to divide the value ofmapData.keyX.subkeyX[0], is that correct?