From f35c6fd75ac3b0f1c118aa7492d6f8f6b6182dbb Mon Sep 17 00:00:00 2001 From: Olatunji Clement Date: Tue, 31 Jan 2023 15:56:01 +0100 Subject: [PATCH] Olatunji Clement --- src/morse/index.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/morse/index.js b/src/morse/index.js index cf65063..cccb595 100644 --- a/src/morse/index.js +++ b/src/morse/index.js @@ -56,8 +56,24 @@ const MORSE_CODE = { "...---...": "SOS", }; -Object.freeze(MORSE_CODE); - -function morse(text) {} +decodeMorse = function(morseCode){ + morseCode = morseCode.trim(); + let splitCode = morseCode.split(' '); + let result = []; + + for (let i = 0; i < splitCode.length; i++) { + let words = splitCode[i].split(' '); + for (let j = 0; j < words.length; j++) { + if (MORSE_CODE[words[j]]) { + result.push(MORSE_CODE[words[j]]); + } + } + + if (i !== splitCode.length - 1) { + result.push(' '); + } + } + return result.join(''); +} module.exports = morse;