Improve Morse Translator and Letter Translator

This commit is contained in:
Daniel Odendahl Jr
2017-04-12 20:40:03 +00:00
parent 4667ac8b44
commit 67576df0e3
2 changed files with 11 additions and 7 deletions
+3 -4
View File
@@ -3,7 +3,7 @@ module.exports.wordTrans = (text, words) => {
let translation = [];
for (let i = 0; i < text.length; i++) {
const word = text[i].toLowerCase();
const wordPuncStrip = word.replace(/[.,?!]/g, '');
const wordPuncStrip = word.replace(/[\[\\^$.|?*+()\]]/g, '');
if (words[wordPuncStrip]) {
const reg = new RegExp(wordPuncStrip, 'gi');
translation.push(word.replace(reg, words[wordPuncStrip]));
@@ -19,10 +19,9 @@ module.exports.letterTrans = (text, letters) => {
text = text.split('');
let translation = [];
for (let i = 0; i < text.length; i++) {
const letter = text[i].toLowerCase();
const letter = text[i];
if (letters[letter]) {
const reg = new RegExp(letter, 'gi');
translation.push(letter.replace(reg, letters[letter]));
translation.push(letters[letter]);
}
else {
translation.push(letter);