Hyebin‘s blog

Detail

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.

 

<code>

function disemvowel(str) {
  return str.replace(/[aeiouAEIOU]/gi, "");
}

 

<other code>

function disemvowel(str) {
  var vowels = ['a', 'e', 'i', 'o', 'u'];
  
  return str.split('').filter(function(el) {
    return vowels.indexOf(el.toLowerCase()) == -1;
  }).join('');
}
const vowels = 'aeiou';

function disemvowel(str) {
  return str
    .split('')
    .filter(letter => !vowels.includes(letter.toLowerCase()))
    .join('');
}

'Algorithm > Codewars' 카테고리의 다른 글

[Codewars/JS] Convert string to camel case  (0) 2022.01.30
[Codewars/JS] Convert string to camel case  (0) 2022.01.30
[Codewars/JS] Find the odd int  (0) 2022.01.20
[Codewars/JS] Vowel Count  (0) 2022.01.18
[Codewars/JS] Moving Zeros To The End  (0) 2022.01.14
profile

Hyebin‘s blog

@hyebin Lee

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그