字母数字排序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字母数字排序相关的知识,希望对你有一定的参考价值。
function sortAlphaNum(a, b) { var x = a.split("/"); var y = b.split("/"); x = x[x.length-1].replace(/\s/g," ").split(/(d )/); // the split formatting is imperative, everything else can change y = y[y.length-1].replace(/\s/g," ").split(/(d )/); // the split formatting is imperative, everything else can change for (var i in x) { if (x[i] && !y[i] || isFinite(x[i]) && !isFinite(y[i])) { return -1; } else if (!x[i] && y[i] || !isFinite(y[i]) && isFinite(y[i])) { return 1; } else if (!isFinite(x[i]) && !isFinite(y[i])) { x[i] = x[i].toLowerCase(); y[i] = y[i].toLowerCase(); if (x[i] < y[i]) return -1; if (x[i] > y[i]) return 1; } else { x[i] = parseFloat(x[i]); y[i] = parseFloat(y[i]); if (x[i] < y[i]) return -1; if (x[i] > y[i]) return 1; } } return 0; }
以上是关于字母数字排序的主要内容,如果未能解决你的问题,请参考以下文章