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);
참고개념
- Array.replace()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
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
'Frontend > JS100 문제풀이' 카테고리의 다른 글
[JS100] 41번 문제 소수판별 (0) | 2023.04.12 |
---|---|
[JS100] 40번 문제 놀이기구 (0) | 2023.04.11 |
[JS100] 38번 문제 3등까지 사탕 (0) | 2023.04.09 |
[JS100] 37번 문제 반장선거 (0) | 2023.04.08 |
[JS100] 36번 문제 구구단 출력 (0) | 2023.04.07 |