0
Replace a vowel with " *" from an array - JavaScript
Hello Coders, I'm trying to write a function, that will take an array as a parameter. I want to return a new array, but with vowels replaced by '*'. Example : ["h', "i"] => should be ["h", "*"] Please help! https://code.sololearn.com/W0IE6syyufrE
3 ответов
+ 3
result.push(arr[i]);
this line must be outside the if statement. 
actually here you don't need "result" array because you are replacing vowels with "*"  in original array itself, so instead of "result"  you can return "arr" array.
+ 2
function replaceVowels (arr) {
 let vowels = ['a', 'e', 'i', 'o', 'u'];
 let result =[];
 for ( let i=0; i< arr.length; i++) {
   if (vowels.includes(arr[i])) {
	 result.push("*");
   }
   else {
     result.push(arr[i])
   }
 }
 return result;
}
console.log (replaceVowels(["h", "i"]));
0
Thank you so much for helping me out!!





