Created
January 6, 2015 17:09
-
-
Save psyark/b93e37bd477f3f9aeea9 to your computer and use it in GitHub Desktop.
AtomのTree Viewのソート順を文字/数字を交互に判定するように変更
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// names.sort(function(name1, name2) { | |
// return name1.toLowerCase().localeCompare(name2.toLowerCase()); | |
// }); | |
names.sort(function(name1, name2) { | |
var a1 = name1.split(/(\d+)/); | |
var a2 = name2.split(/(\d+)/); | |
for (var i=0; i<Math.max(a1.length, a2.length); i+=2) { | |
var ra = (a1[i] || '').localeCompare(a2[i] || ''); | |
var rd = a1[i+1] == a2[i+1] ? 0 : (a1[i+1] * 1 > a2[i+1] * 1 ? 1 : -1); | |
if (ra || rd) { | |
return ra || rd; | |
} | |
} | |
return 0; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
みたいにしてくれる。ファイル名中のフィールドが固定されてれば日付とかも良い感じになる