From ce9ec674ab000795e9c244ab7e5d25757639f610 Mon Sep 17 00:00:00 2001 From: JuneHee Date: Tue, 7 May 2024 21:39:54 +0900 Subject: [PATCH] =?UTF-8?q?[PGM]=20[3=EC=B0=A8]=20=EC=95=95=EC=B6=95=20/?= =?UTF-8?q?=20Level=202=20/=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[3\354\260\250] \354\225\225\354\266\225.js" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "junehee/[3\354\260\250] \354\225\225\354\266\225.js" diff --git "a/junehee/[3\354\260\250] \354\225\225\354\266\225.js" "b/junehee/[3\354\260\250] \354\225\225\354\266\225.js" new file mode 100644 index 0000000..7a763e6 --- /dev/null +++ "b/junehee/[3\354\260\250] \354\225\225\354\266\225.js" @@ -0,0 +1,16 @@ +function solution(msg) { + const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); + const answer = []; + + for (let i = 0; i < msg.length; i++) { + for (let j = msg.length; j > i; j--) { + if (alphabet.includes(msg.slice(i, j))) { + alphabet.push(msg.slice(i, j + 1)); + answer.push(alphabet.indexOf(msg.slice(i, j)) + 1); + i += (j - i - 1); + } + } + } + + return answer; +}