-
Notifications
You must be signed in to change notification settings - Fork 0
/
kakao 신규아이디 추천 .js
45 lines (39 loc) · 1.03 KB
/
kakao 신규아이디 추천 .js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function solution(new_id) {
let answer = '';
const reg = /[\{\}\[\]\/?,;:|\)*~`!^\+<>@\#$%&\\\=\(\'\"]/gi
answer = new_id
.toLowerCase()
.replace(reg,"")
.replace("...",".")
.replace("..",".")
if(answer[0] === "."){
answer = answer.slice(1,answer.length);
}
if(answer === ""){
for(let i = 0 ; i < new_id.length ; i++){
answer += "a";
}
}
if(answer.length >= 16){
console.log(answer)
for(let i = answer.length-1; i >0 ; i--){
answer = answer.replace(answer[i],'')
if(i == 15){
break;
}
}
}
if(answer[answer.length-1] === "."){
answer = answer.replace(answer[answer.length-1] , '')
}
if(answer.length <3){
let lastStr = answer[answer.length-1];
for(let k = 0 ; k <= 3 ; k++){
answer += lastStr
if(answer.length >= 3){
break;
}
}
}
return answer;
}