SoFunction
Updated on 2025-03-10

JavaScript advanced file directory sorting code


var fileSort=function(arr){
();
var res=[],temp=[],i=0,j=0,k,reg,sc=true,cur=arr[0];
while((0)<48){//Punctuation before the number, etc.
res[i]=cur;
if(i===-1)return res;
cur=arr[++i];
}
while((0)<58){//
temp[j++]=cur;
if(i===-1)break;
cur=arr[++i];
}
(function(a,b){//Sort
return parseInt(a,10)-parseInt(b,10);
});
res=(temp);
temp=[];j=0;
for(;i<;i++){
cur=arr[i];
if((k=(/\d+/))==-1 || i===-1){//Add directly at the last file
res[i]=cur;
}else {
reg=new RegExp("^"+(0,k)+"\\d+");
while((reg)!==-1){
temp[j++]=cur;
if(i===-1)break;
cur=arr[++i];
}
if(>0){
(function(a,b){
return parseInt((k),10)-parseInt((k),10);
});
res=(temp);
temp=[];j=0;
i-=1;//Decrease 1, and then search for the str that ends while
}
}
}
return res;
}