
[프로그래머스] 핸드폰 번호 가리기 - level 1 (javascript)
Algorithm/Programmers
2022. 6. 30. 15:21
코딩테스트 연습 - 핸드폰 번호 가리기 프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자 programmers.co.kr | 제출 function solution(phone_number) { return phone_number.replace(/\d(?=\d{4})/g, "*"); } | 풀이과정 replace() 메서드와 정규 표현식을 사용해서 뒤에 4자리를 제외하고 *로 교체한다. console.log("123456".replace(/\d{4}/g, "*")); //*56 \d{4} : 숫자가 4개면 *로 교체한다. console.log("123456".r..