const solution = (phone_number) => {
const lastFourDigit = phone_number.substr(phone_number.length - 4);
const restLength = phone_number.length - lastFourDigit.length;
let stars = '';
for(let i = 0; i < restLength; i++) {
stars += '*';
}
return stars + lastFourDigit;
};
substr()
👎👎👎👎👎
...
substr() 사용하지말자...
function solution(phone_number) {
return s.replace(/\d(?=\d{4})/g, "*");
}
function solution(phone_number){
var result = "*".repeat(s.length - 4) + s.slice(-4);
return result;
}