From 942d53d4f4cdd42758c3d1faecf3e00d9fa790ca Mon Sep 17 00:00:00 2001 From: PancakePhilarmonych Date: Wed, 22 Nov 2023 00:12:23 +0400 Subject: [PATCH] feat: improve getRandomColor function --- src/utils/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 533598b..52da2fa 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -32,9 +32,10 @@ const mainColors = [ Colors.EMPTY, ]; -export const getRandomColor = () => { - const index = Math.floor(Math.random() * mainColors.length); - return mainColors[index]; +export const getRandomColor = (excludeEmpty = false) => { + const colors = excludeEmpty ? mainColors.filter(color => color !== Colors.EMPTY) : mainColors; + const index = Math.floor(Math.random() * colors.length); + return colors[index]; }