]> git.cworth.org Git - empires-server/commit
generate_id: Use Array.fill(null) to initialize an array of null values
authorCarl Worth <cworth@cworth.org>
Wed, 27 May 2020 03:39:20 +0000 (20:39 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 27 May 2020 03:39:20 +0000 (20:39 -0700)
commita5dd0c5e612311132f053b71f32a1fe94e5819d3
tree0af132a5f9858d9502a3f9e8948dbce58528a3e2
parentd04124365041fb3d9606a0aa56b49a2147565038
generate_id: Use Array.fill(null) to initialize an array of null values

When I first wrote this code I reached for a construct of:

Array(4).map(...)

but I found that map doesn't work on an array of empty items like
this. To get things to work I instead used:

[null, null, null, null].map(...)

which did the trick, but only because I happened to be using a
sufficiently small size that it was reasonable to type the complete
literal. For this commit I've found a cleaner approach of:

Array(4).fill(null).map(...)
lmno.js