在js中对数字和字母进行排序

Sorting for both numbers and alphabets in js

productID = '65,78,98,565,12,546,879,456123,456,987,1,312,45,8,546,123,0,165,4566'; productID = 'asd,sad,d,s,as,e,ew,qw,asd,xsad,sad,sad,asd,eqw,sda,ds,wqe,sda,sad,wqewq';


multipleProducts = productID.split(',').sort().sort(function(a, b){return a - b}); productID = multipleProducts.join(','); console.log(productID)

这个js函数我能转多少 有没有人能在任何场景下找到或破解这个函数

productID = '65,78,98,565,12,546,879,456123,456,987,1,312,45,8,546,123,0,165,4566'; productID2 = 'asd,sad,d,s,as,e,ew,qw,asd,xsad,sad,sad,asd,eqw,sda,ds,wqe,sda,sad,wqewq';


multipleProducts = productID.split(',').sort(sortNumbers).join(','); 
console.log(multipleProducts)
multipleProducts2 = productID2.split(',').sort(sortString).join(','); 
console.log(multipleProducts2)

function sortString(a, b){return a > b ? 1 : -1}
function sortNumbers(a,b){return (+a) > (+b) ? 1 : -1}

如果值为 isFinite,则可以通过将值转换为数字来采用尊重数字和字符串的排序函数,否则采用字符串。

const
    ASC = (a, b) => a > b || -(a < b)
    ASC_BY_TYPE = (...p) => ASC(...p.map(v => isFinite(v) ? +v : v));

var productID0 = '65,78,98,565,12,546,879,456123,456,987,1,312,45,8,546,123,0,165,4566',
    productID1 = 'asd,sad,d,s,as,e,ew,qw,asd,xsad,sad,sad,asd,eqw,sda,ds,wqe,sda,sad,wqewq';


console.log(productID0.split(',').sort(ASC_BY_TYPE).join());
console.log(productID1.split(',').sort(ASC_BY_TYPE).join());