Is there a more efficient/ concise/ eloquent way to write this:
else if ((aInd === 3)||(aInd === 7)||(aInd === 9)||(aInd === 19)
letter = alphabet[aInd + 1].toUpperCase();
Is there any valid syntax that looks like
if (a === (3 || 7 || 13 || 19) {do this}
... or lets you group sets of values of for a single variable in a more concise way than a bunch of boolean expressions with || logic?
Background: Novice programmer, working through a basic cypher challenge on coderbyte that requires taking a certain action (capitalizing) if the letter is a vowel. For reasons of simplicity (because it's used elsewhere in the program) I declared an array alphabet containing each letter a-z in the form of a string. The 'cypher' also transposes every letter one to the right, so the alphabet indexes of the letters to become vowels are 3, 7, 13, and 19. aInd represents the index of letter in the alphabet.
Full code:
function letterChanges(str) {
var alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var words = str.toLowerCase().split(' '), senArray = words.map(function(word) {return word.split('')});
senArray.forEach(function(word) {
word = word.filter(function(letter, index, word) {
if ((Boolean(alphabet.indexOf(letter))) === false) return false;
else return true;
});
});
senArray[0].map(function(letter) {
var aInd = alphabet.indexOf(letter);
switch (aInd) {
case 25:
letter = alphabet[aInd].toUpperCase();
break;
case (3 || 7 || 13 || 19):
letter = alphabet[aInd + 1].toUpperCase();
console.log(letter);
break;
default:
letter = alphabet[aInd + 1];
break;
}
return letter;
})
return senArray.map(function(word) {
return word.map(function(letter) {
var aInd = alphabet.indexOf(letter);
if (aInd === 25) {letter = alphabet[aInd].toUpperCase();}
else if ((aInd === 3)||(aInd === 7)||(aInd === 13)||(aInd === 19)) {letter = alphabet[aInd + 1].toUpperCase();}
else {letter = alphabet[aInd + 1];}
return letter;
}).join('');
}).join(' ');
}
letterChanges("Input string goes here.");