Added special charactrs array

This commit is contained in:
billalp 2019-10-28 11:17:07 +00:00
parent 103a4e2b34
commit 48186acc19
1 changed files with 3 additions and 6 deletions

View File

@ -1,6 +1,7 @@
const caesar = function(value, addBy) { const caesar = function(value, addBy) {
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
const specialChars = [' ', '!', ','];
const valueLowerCase = value.toLowerCase(); const valueLowerCase = value.toLowerCase();
const valueArray = valueLowerCase.split(''); const valueArray = valueLowerCase.split('');
@ -12,12 +13,8 @@ const caesar = function(value, addBy) {
let finalIndex = letterIndex + addBy; let finalIndex = letterIndex + addBy;
newArr.push(alphabet[finalIndex]); newArr.push(alphabet[finalIndex]);
} else if (valueArray[i].includes(' ')) { } else if (specialChars.includes(valueArray[i])) {
newArr.push(' '); newArr.push(valueArray[i]);
} else if (valueArray[i].includes('!')) {
newArr.push('!');
} else if (valueArray[i].includes(',')) {
newArr.push(',');
} else { } else {
// return 'is not a part of the alphabet'; // return 'is not a part of the alphabet';
return 'no'; return 'no';