1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { sum } from "https://esm.town/v/stevekrouse/sum";
import { testCSVGroupByShippingData } from "https://esm.town/v/stevekrouse/testCSVGroupByShippingData";
import { groupBy } from "https://esm.town/v/stevekrouse/groupBy";
export let exampleGroupByShppingCSV = (async () => {
const groups = await Promise.all(Object.entries(
await groupBy(
testCSVGroupByShippingData,
"Service Type"
)
).map(([type, items]) =>
[type, (items as any[]).map((i) => parseFloat(i["Net Charge Amount"]))]
).map(async ([type, items]) => [type, await sum(items)]));
let total = await sum(groups.map(([_, amount]) => amount))
return Object.fromEntries([...groups, ['Sum Total', total]])
})()
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.