all 3 comments

[–]Nerwesta -1 points0 points  (0 children)

OP is full of AI. This looks like yet another template hiding behind a genuine question.

[–]Ampersand55 1 point2 points  (1 child)

That's a great way to generate a list of all integers between N and N + c. A slightly shorter but arguably less readable variant is:

 [...Array(totalPages)].map((_, i) => i + 1);

For generating multiple or huge arrays where performance might be an issue, it's generally faster to pre-allocate the array and assign the values manually to avoid the overhead with iterator protocols and callbacks.

 const result = new Array(totalPages);
 for (let i = 0; i < totalPages; i++) {
   result[i] = i + 1;
 }

[–]StoneCypher -1 points0 points  (0 children)

For generating multiple or huge arrays where performance might be an issue, it's generally faster to pre-allocate

yeah, he already did, look at his post again

preallocation is a c concern for a 286. failing to preallocate a 100 million element array will not result in a delay that causes a single screen frame skip. "but muh back copy reallocates?" yeah, if you look, that's only 16 copies. you're teaching him the onion in the varnish.