Files
apify--crawlee/docs/examples/reduce.ts
T
Jan Buchar 5db533afdb chore: use biome for code formatting (#2301)
This takes ~50ms on my machine 🤯 

- closes #2366 
- Replacing spaces with tabs won't be done right here, right now.
- eslint and biome are reconciled
- ~biome check fails because of typescript errors - we can either fix
those or find a way to ignore it~
2024-05-22 11:00:43 +02:00

31 lines
752 B
TypeScript

import { Dataset, KeyValueStore } from 'crawlee';
const dataset = await Dataset.open<{
url: string;
headingCount: number;
}>();
// Seeding the dataset with some data
await dataset.pushData([
{
url: 'https://crawlee.dev/',
headingCount: 11,
},
{
url: 'https://crawlee.dev/storage',
headingCount: 8,
},
{
url: 'https://crawlee.dev/proxy',
headingCount: 4,
},
]);
// calling reduce function and using memo to calculate number of headers
const pagesHeadingCount = await dataset.reduce((memo, value) => {
return memo + value.headingCount;
}, 0);
// saving result of map to default Key-value store
await KeyValueStore.setValue('pages_heading_count', pagesHeadingCount);