Replace a vowel with " *" from an array - JavaScript | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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

19th Sep 2019, 8:38 PM
Jojo
Jojo - avatar
3 Réponses
+ 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.
19th Sep 2019, 8:56 PM
nidhi
+ 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"]));
19th Sep 2019, 8:50 PM
Russ
Russ - avatar
0
Thank you so much for helping me out!!
19th Sep 2019, 8:58 PM
Jojo
Jojo - avatar