4 ms·
Regarding 1: I think the sorting approach is actually really nice in this case. Clearly it's not as efficient as a simple loop, but it's safer and more readable
by nunull 10y ago
Regarding 1: I think the sorting approach is actually really nice in this case. Clearly it's not as efficient as a simple loop, but it's safer and more readable. Explicit looping and mutation can introduce nasty bugs which this kind of declarative approach can't.
- ola 10y agoI am of the same opinion, always go for correctness before performance, efficiency can be tuned later if it's even needed.
- madflame991 10y agoNo need to mutate/slice/sort anything Math.max(...lines.map((line) => ctx.measureText(line).width))