본문 바로가기
알고리즘/Codewars

[Codewars] Disemvowel Trolls (7 kyu) / JavaScript

by fluss 2022. 10. 5.

https://www.codewars.com/kata/52fba66badcd10859f00097e

 

Codewars - Achieve mastery through coding practice and developer mentorship

Coding practice for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

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.

 

설명:

트롤이 당신의 말을 공격했습니다!

이 상황을 대처하는 일반적인 방법은 트롤의 말에서 모든 모음을 제거해 위험을 무효화하는 것입니다.

당신은 문자열을 받아서 모든 모음이 제거된 새로운 문자열을 반환하는 함수를 작성해야 합니다.

예를 들어, "This website is for losers LOL!"라는 문자열은 "Ths wbst s fr lsrs LL!"가 되어야 합니다.

참고: 이 kata에서는 y는 모음으로 고려되지 않습니다.

 

해설

function disemvowel(str) {
  return str.replace(/[aeiou]/ig, '');
}

사이의 문자 중 하나를 선택하는 [] 안에 모음 aeiou를 넣고 대소문자를 따지지 않는 i, 모든 모음을 찾기 위해 g를 쓴다. 그리고 replace를 사용해 위와 같은 조건에 해당할 때 공백으로 바꿔준다. 

 

참고

https://ko.wikipedia.org/wiki/%EC%A0%95%EA%B7%9C_%ED%91%9C%ED%98%84%EC%8B%9D

 

정규 표현식 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 노란색 강조 부분은 다음 정규식을 사용했을 때 매치된 것이다. 정규 표현식(正規表現式, 영어: regular expression, 간단히 regexp[1] 또는 regex, rational expression)[2][3] 또

ko.wikipedia.org

https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Regular_Expressions

 

정규 표현식 - JavaScript | MDN

정규 표현식, 또는 정규식은 문자열에서 특정 문자 조합을 찾기 위한 패턴입니다. JavaScript에서는 정규 표현식도 객체로서, RegExp의 exec()와 test() 메서드를 사용할 수 있습니다. String의 match(), matchA

developer.mozilla.org

 

댓글