본문 바로가기
JavaScript/메소드

[javascript] 모음제거, replaceAll(), replace(), 정규식 연습

by Angry Stock 2023. 9. 13.
반응형
연습
function solution1(string) {
  let letter = ['a', 'e', 'i', 'o', 'u'];
  letter.map((e) => {
    string = string.replaceAll(e, '');
  });
  return string;
}

function solution2(string) {
  return string.replace(/[aeiou]/g, '');
}

let string = ['Did you receive my purchase order?', 'Yes. I checked the e-mail just now.'];

for (let i = 0; i < string.length; i++) {
  console.log('solution1', solution1(string[i]));
}
for (let i = 0; i < string.length; i++) {
  console.log('solution2', solution2(string[i]));
}
결과

반응형

댓글