function solution(files) {
const parseFile = file => {
let head = ''
let number = ''
let tail = ''
let current = 0;
for(let i=0; i<file.length;i ++){
const char = file[i]
const code = char.charCodeAt();
if(code > 47 && code <58){
number += char;
}else{
if(number.length > 0) break;
head += char;
}
}
return [head, number]
}
return files.map((file, i) =>{
const [head, number] = parseFile(file)
return ([{
head: head.toLowerCase(),
number: +number}, i])
}).sort((a,b) => {
const fileA = a[0]
const fileB = b[0]
if(fileA.head > fileB.head) return 1
if(fileA.head < fileB.head) return -1
if(fileA.number > fileB.number) return 1
if(fileA.number < fileB.number) return -1
return 0
}).map(([file, i]) => files[i])
}