Comment

Comment by returningfory2

I disagree in the sense that you can rewrite the code to use the trick and also not allocate in advance. Nothing about the trick requires you to allocate up front: before writing to out[n] you can extend the vector if it’s out of bounds. Or, after incrementing n, do out.push(0).

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton