Flatten in dvjs

What can I say, …well, I have become weak.
For fun, I asked the great AI oracle chatopenAI…
It spat out the code without flinching.
What that means for the future - not only here in the forum - I dare not imagine. :flushed:

Well, for all those who might be looking for something similar, here is the solution:

```dataviewjs
let groupedThema = {}
dv.pages()
    .where(p => p.MusType == "Vortrag" || p.MusType == "Lesung")
    .forEach(page => {
        if(!Array.isArray(page.thema)) {
            page.thema = [page.thema];
        }
        for (let t of page.thema) {
            if (!groupedThema[t]) {
                groupedThema[t] = []
            }
            groupedThema[t].push({
                file: page.file,
                jahr: page.jahr,
                alias: page.alias
            });
        }
    });

let sortedThema = Object.keys(groupedThema).sort((a, b) => groupedThema[b].length - groupedThema[a].length)

for (let key of sortedThema) {
        dv.header(3, key + " (" + groupedThema[key].length + ")");
        dv.table(["Thema", "Jahr"],
            groupedThema[key]
                .sort((a, b) => b.jahr - a.jahr)
                .map(p => ["[[" + p.file.path + "|" + p.alias + "]]", p.jahr]));
    }

gives this output, what I can live with.

until next time, community, I will remain faithful to you, the AI thingy doesn’t sit well with me… but it’s “progress”.

Thanks to all who have nevertheless passed by…

1 Like