Created
February 8, 2022 13:06
-
-
Save fadihanna123/1f67b5196465f40ddd5f4c95ece81a8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 materialTypeReducer = (acc: { [materialType: string]: number }, current: Silo) => { | |
const material = current.material.replace(" ", ""); | |
if (Object.keys(acc).indexOf(material) === -1) { | |
acc[material] = current.weight; | |
} | |
else { | |
acc[material] += current.weight; | |
} return acc; | |
}; | |
const materialTypeObj = this.silos.filter((item) => item.material).reduce(materialTypeReducer, {} as { [materialtype: string]: number }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment