How to find all the vowels in an array

How to find all the vowels in an array
0

#1
function LetterChanges(str) { 
    
    var newArray = [];
    
    str=str.toLowerCase();

for ( var i = 0; i < str.length; i++){
 newArray[i] = str.charCodeAt(i);

}
var  updatedArray = newArray.map(function(item){
    if(item === 32){
    return item
    }else return item + 1;
});
var change = String.fromCharCode.apply(null,updatedArray);

var correct1 =  String.fromCharCode.apply(null , updatedArray);
var changeZ =  correct1.replace(/['{']/g , 'a')


//This is where I search for vowels 
for (var k = 0; k < changeZ.length; k++){
    if (changeZ[i] === 'a' || changeZ[i] === 'e' || changeZ[i] === 'i' ||changeZ[i] === 'o' || changeZ[i] === 'u'){
        changeZ.replace(changeZ[i].toUpperCase())
    }

} 
return changeZ;
}

// keep this function call here 
LetterChanges(readline()); 

I have been stuck on this all day today. I feel like the answer is on the tip of my fingers. Please help. Thank you in advance!

Here is the challenge question:
Using the JavaScript language, have the function LetterChanges(str) take the str parameter being passed and modify it using the following algorithm. Replace every letter in the string with the letter following it in the alphabet (ie. c becomes d, z becomes a). Then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string.


#2

.replace() requires two arguments. Calling `changeZ.replace(changeZ[i].toUpperCase()) simply won’t work (and it doesn’t modify the string in-place, so you’ll need to assign the result to another variable).

How about using .replace() to replace all vowels? You won’t need a for-loop for that (you could use one, but it’ll get dirty fast).

var changeZ = correct1
  .replace(/['{']/g, 'a')
  .replace(/[aeiou]/g, function(match) {
    return match.toUpperCase();
  });

#3

I assume since you converted the entire string to lower case first, then after the conversion, new letters are not supposed to retain their original case (with the exception being that all letters converted to vowels will always be uppercase).

With that in mind, I think the following solution could work. Don’t peak until you figure out your current working solution. You are close.

function LetterChanges(str) {
  return str.toLowerCase()
    .split('')
    .reduce((newStr,char) => {
      newStr += /[a-z]/.test(char) ? String.fromCharCode(((char.charCodeAt() - 96) % 26) + 97 ) : char;
      return newStr;
      },'')
    .replace(/[aeiou]/g, vowel => vowel.toUpperCase());
}

LetterChanges('xy z'); // results in 'yz A'

#4

Damn! I thought I could pass it unfortunate that was not the case. Apparently it wants me to keep special characters the same like ‘$’ '@'etc. a few solution I was thinking is subtracting my charCodes by one after the map functions added 1 to all. However it just seems like a lazy and the wrong way to do it. Any idea on how this can be done. Can anyone give me a hint to right direction.

function LetterChanges(str) { 
 var newArray = [];
    
    str=str.toLowerCase();

for ( var i = 0; i < str.length; i++){
 newArray[i] = str.charCodeAt(i);

}
var  updatedArray = newArray.map(function(item){
    var charCodes = [32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,91,92,93,94,95,96,123,124,124,125,126];

 for ( var x = 0; x < charCodes.length; x++){
     for( var y = 0; y < newArray.length; y++) {
         
         if(newArray[y] === (charCodes[x])){
             return item;
         
     }else return item + 1;
    
 }
}
});





var change = String.fromCharCode.apply(null,updatedArray);

var correct1 =  String.fromCharCode.apply(null , updatedArray);
var changeZ =  correct1.replace(/['{']/g , 'a').replace(/[aeiou]/, function(match){
    return match.toUpperCase();
})

return changeZ;
}

  // code goes here  
 
         

   
// keep this function call here 
LetterChanges(readline());                            


#5

Instead of listing char codes, your best bet would be using regex to match all letters. If all letters in the input need to be lowercased first, it’ll make things much simpler. All you have to do is to use .replace() on the original string, supply a regex that will match all letters in the string, then provide a callback function to shift the matches one letter.

// The regex here will match all letters in `str`.
var shiftedString = str.replace(/[a-z]g/, function(letterMatch) {
  // Do the shifting on `letterMatch` here.
});