Description
- Your task is to write a function that takes a string and return a new string with all vowels removed.
- 모든 모음(vowel)이 제거된 새로운 문자열을 반환한다.
Solution 01
function removeVowels(str) {
const vowels = 'aeiouAEIOU';
let result = '';
for (let i = 0; i < str.length; i++) {
if (vowels.indexOf(str[i]) === -1) {
result += str[i];
}
}
return result;
}
removeVowels('Hello World'); // Hll Wrld
removeVowels('Codewars'); // Cdwrs
removeVowels('Abracadabra'); // brcdbr
Solution 02
function removeVowels(str) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
return str.split('').filter(i => {
return vowels.indexOf(i.toLowerCase()) === -1;
}).join('');
}
removeVowels('Hello World'); // Hll Wrld
removeVowels('Codewars'); // Cdwrs
removeVowels('Abracadabra'); // brcdbr
Solution 03
function removeVowels(str) {
return str.replace(/[aeiouAEIOU]/g, '');
}
removeVowels('Hello World'); // Hll Wrld
removeVowels('Codewars'); // Cdwrs
removeVowels('Abracadabra'); // brcdbr