Skip to content

Instantly share code, notes, and snippets.

@fadihanna123
Created February 8, 2022 13:06
Show Gist options
  • Save fadihanna123/1f67b5196465f40ddd5f4c95ece81a8d to your computer and use it in GitHub Desktop.
Save fadihanna123/1f67b5196465f40ddd5f4c95ece81a8d to your computer and use it in GitHub Desktop.
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