function solution(files) {
let fileWrap = files.map((file, index) => ({ file, index }));
const compare = (a, b) => {
const reg = /(\D*)([0-9]*)/i;
const A = a.match(reg);
const B = b.match(reg);
const compareHead = A[1].toLowerCase().localeCompare(B[1].toLowerCase());
const compareNumber = (a, b) => {
if (parseInt(a) > parseInt(b)) return 1;
else if (parseInt(b) > parseInt(a)) return -1;
else return 0
}
return compareHead === 0 ? compareNumber(A[2], B[2]) : compareHead;
}
fileWrap.sort((a, b) => {
let result = compare(a.file, b.file)
return result === 0 ? a.index - b.index : result
})
return fileWrap.map(e => e.file);
}