-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewId.js
More file actions
30 lines (29 loc) · 750 Bytes
/
newId.js
File metadata and controls
30 lines (29 loc) · 750 Bytes
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
//my-answer
function solution(new_id) {
let answer = new_id
.toLowerCase()
.replace(/[^a-z0-9-_.]/gi, "")
.replace(/[.]{2,}/gi, ".")
.replace(/^[.]|[.]$/gi, "");
if (answer === "") answer = "a";
if (answer.length > 15) {
answer = answer.substring(0, 15);
answer = answer.replace(/[.]$/gi, "");
}
while (answer.length < 3) {
answer += answer[answer.length - 1];
}
return answer;
}
//best-case
// const solution = (new_id) => {
// const id = new_id
// .toLowerCase()
// .replace(/[^\w\d-_.]/g, '')
// .replace(/\.{2,}/g, '.')
// .replace(/^\.|\.$/g, '')
// .padEnd(1, 'a')
// .slice(0, 15)
// .replace(/^\.|\.$/g, '')
// return id.padEnd(3, id[id.length-1])
// }