Last active
September 26, 2018 11:35
-
-
Save santospatrick/162e43f6c25f235020e248826fc32ddf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const names = cultures.map(item => item.cultureName) | |
// ['Soybean', 'Maize', 'Wheat'] | |
const energies = cultures | |
.reduce((acc, nextObject) => { | |
const nextValue = nextObject.energy.quantity; | |
const currentValue = acc[nextObject.energy.unit] | |
? acc[nextObject.energy.unit].quantity | |
: 0; | |
acc[nextObject.energy.unit] = { | |
quantity: currentValue + nextValue, | |
}; | |
return acc; | |
}, {}) | |
// { kJ: { quantity: 1728 }, g: { quantity: 0 } } | |
const totalQuantity = cultures | |
.filter(item => item.quantity) | |
.reduce((acc, nextObject) => acc + nextObject['quantity'], 0); | |
// 2700.80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment