When I watch Google Chrome Developers, https://youtu.be/qaGjS7-qWzg?t=636
They said this snippet is not pure. I don't know why.
const g = new Map();
for (const [u,v] of edges) {
if (!g.has(u))
g.set(u, []);
if (!g.has(v))
g.set(v, []);
g.get(u).push(v)
}
And they also mentioned this is pure,
const startPoints = new Set(edges.map(([u, v]) => u));
const g = new Map(
[...startPoints].map(startPoint =>
edges.filter(([u, v]) => u == startPoint).map(([u, v]) => v)
)
);