DESCRIPTION
Trolls are attacking your comment section!
A common way to deal with this situation is to remove all of the
vowels from the trolls’ comments, neutralizing the threat.
Your task is to write a function that takes a string and return a new
string with all vowels removed.
For example, the string “This website is for losers LOL!” would
become “Ths wbst s fr lsrs LL!”.
Note: for this kata y isn’t considered a vowel.
SOLUTION
- 方法一:字符串的
replace()
和 replaceAll()
方法都可,这两个方法都是返回一个新的字符串。
replace()
字符串模式只会被替换一次。要执行全局搜索和替换,请使用带有 g
标志的正则表达式或使用 replaceAll()。
1 2 3 4 5 6
| function disemvowel(str) { let regex = /aeiou/gi; let result = str.replace(regex, ""); return result; }
|