본문 바로가기
Frontend/JS100 문제풀이

[JS100] 39번 문제 q를 e로

by 민두이 2023. 4. 10.
728x90
반응형

Q.39

혜원이는 평소 영타가 빠르고 정확한 것을 친구들에게 자랑하고 다녔습니다.
반 친구들이 혜원이의 타자 속도가 빠르다는 것을 모두 알게 되자 혜원이는 모두의 앞에서 타자 실력을 보여주게 됩니다.
그런데 막상 보여주려니 긴장이 되서 문장의 모든 e를 q로 잘못 친 것을 발견했습니다.
혜원이는 프로그램을 돌려 재빠르게 모든 q를 e로 바꾸는 프로그램을 작성하려고 합니다.
문장이 입력되면 모든 q를 e로 바꾸는 프로그램을 작성해 주세요

입출력

입력 : querty
출력 : euerty

입력 : hqllo my namq is hyqwon
출력 : hello my name is hyewon​

Answer

더보기
let input = prompt('입력해주세요').split(' ');

let result = input.map((item) => item.replace('q','e')).join(' ');
console.log(result);

 

참고개념

 

String.prototype.replace() - JavaScript | MDN

The replace() method returns a new string with one, some, or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match. If pattern is a string, only

developer.mozilla.org

 

728x90