신규 아이디 추천

김현민·2021년 9월 12일
0

Algorithm

목록 보기
70/126
post-thumbnail

function solution(new_id) {
  let answer = new_id
    .toLowerCase() 
    .replace(/[^\.a-z0-9-_]/g, "")
    .replace(/\.+/g, ".")
    .replace(/^\.|\.+$/, "")

  if (answer === "") answer = "a"

  answer = answer.slice(0, 15).replace(/\.+$/, "")

  return answer.length > 2
    ? answer
    : answer.padEnd(3, answer[answer.length - 1])
}

console.log(solution("...!@BaT#*..y.abcdefghijklm"))

정규표현식

참고 https://curryyou.tistory.com/234

profile
Jr. FE Dev

0개의 댓글