У меня есть 2 объекта:
const totalConso = [
{ horoseason: 'BASE', value: 0 },
{ horoseason: 'HPH', value: 0 },
{ horoseason: 'HCH', value: 0 },
{ horoseason: 'HPE', value: 5853.16 },
{ horoseason: 'HCE', value: 4460.99 }
]
const totalAutoConso = [ { horoseason: 'HPH', value: 0 },
{ horoseason: 'HCH', value: 0 },
{ horoseason: 'HPE', value: 2354.62 },
{ horoseason: 'HCE', value: 0 }
]
Я бы хотел отдохнуть их значение.
Я могу сделать это так, но это не выглядит очень элегантно
onst totalConsoBase = totalConso.filter(it => it.horoseason === "BASE").shift()
const totalAutoConsoBase = totalAutoConso.filter(it => it.horoseason === "BASE").shift()
const totalConsoHPH = totalConso.filter(it => it.horoseason === "HPH").shift()
const totalAutoConsoHPH = totalAutoConso.filter(it => it.horoseason === "HPH").shift()
const totalConsoHCH = totalConso.filter(it => it.horoseason === "HCH").shift()
const totalAutoConsoHCH = totalAutoConso.filter(it => it.horoseason === "HCH").shift()
const totalConsoHPE = totalConso.filter(it => it.horoseason === "HPE").shift()
const totalAutoConsoHPE = totalAutoConso.filter(it => it.horoseason === "HPE").shift()
const totalConsoHCE = totalConso.filter(it => it.horoseason === "HCE").shift()
const totalAutoConsoHCE = totalAutoConso.filter(it => it.horoseason === "HCE").shift()
console.log(totalConsoBase, totalAutoConsoBase, totalConsoHPH, totalAutoConsoHPH)
const totalGridConso = [
{
horoseason: "BASE",
value: typeof totalConsoBase !== 'undefined' ? totalConsoBase.value - totalAutoConsoBase.value : null
}, {
horoseason: "HPH",
value: typeof totalConsoHPH !== 'undefined' ? totalConsoHPH.value - totalAutoConsoHPH.value : null
}, {
horoseason: "HCH",
value: typeof totalConsoHCH !== 'undefined' ? totalConsoHCH.value - totalAutoConsoHCH.value : null
}, {
horoseason: "HPE",
value: typeof totalConsoHPE !== 'undefined' ? totalConsoHPE.value - totalAutoConsoHPE.value : null
}, {
horoseason: "HCE",
value: typeof totalConsoHCE !== 'undefined' ? totalConsoHCE.value - totalAutoConsoHCE.value : null
},
]
Есть ли способ улучшить мой код?