I was doing this exercise from codewars: https://www.codewars.com/kata/58039f8efca342e4f0000023/train/javascript
Here the instructions:
Create a function that takes a string as a parameter and does the following, in this order:
Replaces every letter with the letter following it in the alphabet (see note below)
Makes any vowels capital
Makes any consonants lower case
Note:
the alphabet should wrap around, so Z becomes A in this kata, y isn't considered as a vowel. So, for example the string "Cat30" would return "dbU30" (Cat30 --> Dbu30 --> dbU30)
function changer(str) {
// happy coding!
let arr = str.split("")
let newArr = [];
let voRegEx = /[aeiouAEIOU]/g;
let conRegEx = /[^aeiouAEIOU]/g;
for(let i = 0; i < arr.length; i++) {
if(arr[i] === "z" || arr[i] === "Z") {
newArr.push("A");
}
else if(arr[i].charCodeAt() >= 95 && arr[i].charCodeAt() <= 121
|| arr[i].charCodeAt() >= 65 && arr[i].charCodeAt() <= 89) {
let char = String.fromCharCode(arr[i].charCodeAt()+1);
console.log(char)
if(conRegEx.test(char)) {
newArr.push(char.toLowerCase());
}
if(voRegEx.test(char)) {
newArr.push(char.toUpperCase());
}
}
else if(typeof(parseInt(arr[i])) === "number") newArr.push(arr[i]);
}
let newStr = newArr.join("")
return newStr;
}
changer("Cat30");
Sry if its too messy, im new to coding and im not to clean yet. The thing is that i console.log(char) and show me the strings "D","b","u" but it seems like the "b" doesn´t get pushed to newArr but if i add 2 chars instead of 1 char now it gets pushed, like changer("Caat30"); now appears the "b" and if i add one other character the next will not appear, and the pattern repeats.
I will gladly aprreciate any answer to my problem. Salute