From 21852cc8d8931fb34100c4be4a8c70d578261fe0 Mon Sep 17 00:00:00 2001 From: Shvedulia Date: Mon, 6 Feb 2023 23:17:46 +0300 Subject: [PATCH] add solution --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index fbeac9bc6..39b2ab66b 100644 --- a/src/index.js +++ b/src/index.js @@ -38,7 +38,17 @@ const MORSE_TABLE = { }; function decode(expr) { - // write your solution here + const resic = [] + for (let i = 0; i < expr.length; i += 10){ + const chunk = expr.slice(i, i + 10) + resic.push(chunk) + } + let result = resic.map(item => { + const key = item.replace(/00/g, "").replace(/10/g, ".").replace(/11/g, "-").replace(/\*\*\*\*\*\*\*\*\*\*/g, " "); + return key === " " ? key : MORSE_TABLE[key] + }); + result = result.join('') + return result } module.exports = {