-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslator.js
38 lines (30 loc) · 961 Bytes
/
translator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//TODO: control errors - translate morse code to words
import morseCode from "./morse-code.js";
const morseCodeKeys = Object.keys(morseCode);
const morseCodeValues = Object.values(morseCode);
export const translateStringToMorse = (inputParam) => {
let translatedString = "";
if (inputParam === null) {
return undefined;
}
if (inputParam.length === 0) {
return "There is no Output without an Input";
}
const inputToLowerCase = inputParam.toLowerCase();
for (let index = 0; index < inputToLowerCase.length; index++) {
const character = inputToLowerCase[index];
for (let index = 0; index < morseCodeKeys.length; index++) {
if (character === morseCodeKeys[index]) {
translatedString += `${morseCodeValues[index]} `;
}
}
}
if (!translatedString) {
return "(Can't find this one😬)";
} else {
return translatedString;
}
};
/*
throw new Error("character to translate not found 👾");
*/