-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreformat.js
More file actions
42 lines (41 loc) · 1.23 KB
/
Copy pathreformat.js
File metadata and controls
42 lines (41 loc) · 1.23 KB
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
/**
* @param {string} s
* @return {string}
*/
var reformat = function(s) {
let result =''
const arr = s.split('')
const isNumber = arr.every(item=>item.charCodeAt() <=57)
const isCharactor = arr.every(item=>{
return item.charCodeAt()>='a'.charCodeAt()&&item.charCodeAt() <=122
})
// console.log(isNumber,isCharactor)
if(s.length === 1) return s;
if(isNumber || isCharactor) return ''
// console.log(arr)
const numbers = arr.filter(item=>item.charCodeAt() <=57)
const charactors = arr.filter(item=>{
return item.charCodeAt()>='a'.charCodeAt()&&item.charCodeAt() <=122
})
console.log(numbers, charactors)
while(numbers.length && charactors.length){
if(charactors.length)
result+=charactors.pop()
if(numbers.length)
result+=numbers.pop()
// result+= charactors.pop()||''+numbers.pop()||''
}
// console.log(result)
if(numbers.length === 1){
result = numbers.pop()+result
}else if(numbers.length >1){
return ''
}else if(charactors.length === 1){
result += charactors.pop()
}else if(charactors.length >1){
return ''
}
console.log(result)
return result
};
reformat("ab123")