From fca93d64b58dac0f4857b7c591c7c2e03ef1184d Mon Sep 17 00:00:00 2001 From: un0211 Date: Sat, 22 Jun 2024 12:51:46 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20generateTagIndex=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/generateTagIndex.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/utils/generateTagIndex.ts diff --git a/src/utils/generateTagIndex.ts b/src/utils/generateTagIndex.ts new file mode 100644 index 00000000..333c649e --- /dev/null +++ b/src/utils/generateTagIndex.ts @@ -0,0 +1,9 @@ +const NUM_TAG_COLORS = 16; + +const generateTagIndex = (tag: string) => { + const asciiList = tag.split('').map((c) => c.charCodeAt(0)); + const sum = asciiList.reduce((a, b) => a + b, 0); + return sum % NUM_TAG_COLORS; +}; + +export default generateTagIndex;