/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; }
URL: http://iaian7.com/
Comments
