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

[Codewars] Remove exclamation marks (8 kyu) / JavaScript

by fluss 2022. 10. 19.

https://www.codewars.com/kata/57a0885cbb9944e24c00008e

 

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:

Write function RemoveExclamationMarks which removes all exclamation marks from a given string.

 

설명:

주어진 문자열에서 모든 느낌표를 제거하는 RemoveExclamationMarks 함수를 작성하세요. 

 

풀이

function removeExclamationMarks(s) {
  return s.replace(/!/g, "");
}

replace를 이용해 모든 느낌표를 제거해주었다.

 

참고

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/replace

 

String.prototype.replace() - JavaScript | MDN

replace() 메서드는 어떤 패턴에 일치하는 일부 또는 모든 부분이 교체된 새로운 문자열을 반환합니다. 그 패턴은 문자열이나 정규식(RegExp)이 될 수 있으며, 교체 문자열은 문자열이나 모든 매치에

developer.mozilla.org

 

댓글