From a5dd0c5e612311132f053b71f32a1fe94e5819d3 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 26 May 2020 20:39:20 -0700 Subject: [PATCH] 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmno.js b/lmno.js index 8e84473..abb1f20 100644 --- a/lmno.js +++ b/lmno.js @@ -56,7 +56,7 @@ class LMNO { } generate_id() { - return [null,null,null,null].map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join(''); + return Array(4).fill(null).map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join(''); } create_game(engine) { -- 2.43.0