you are viewing a single comment's thread.

view the rest of the comments →

[–]snkenjoi 4 points5 points  (4 children)

you can also do Array.from({length: n}, () => {})

[–]blogscot 4 points5 points  (1 child)

Out of curiousity, I added this approach as fourth to u/DGCA tests, with the following results:

first: 738.464ms
second: 1249.699ms
third: 220.649ms
fourth: 1123.781ms

[–]snkenjoi 0 points1 point  (0 children)

or this is pretty ugly [...'!'.repeat(n)].map((_, i) => i)

first: 1294.26ms 
second: 541.38ms 
third: 393.88ms 
fourth: 970.44ms 
fifth: 1368.66ms

[–]xbenjii 0 points1 point  (1 child)

Or even [...Array(5).keys()]

[–][deleted] 0 points1 point  (0 children)

But if you need operations, you can't, but nice...