Last active
May 19, 2017 23:01
-
-
Save arnorhs/e70a16011b346916b6ba822290bb49e4 to your computer and use it in GitHub Desktop.
This file contains 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
function islCompare() { | |
var order = '0123456789aAáÁbBcCdDeEéÉfFgGhHiIíÍjJkKlLmMnNoOóÓpPqQrRsStTuUúÚvVwWxXyYýÝzZþÞæÆöÖ'; | |
function charOrder(a) { | |
var ix = order.indexOf(a); | |
return ix === -1 ? a.codePointAt() + order.length : ix; | |
} | |
return function(a, b) { | |
for (var i = 0; i < Math.min(a.length, b.length); i++) { | |
var iA = charOrder(a[i]); | |
var iB = charOrder(b[i]); | |
if (iA != iB) return iA - iB; | |
} | |
return a.length - b.length; | |
}; | |
} | |
var sorted = ['ab', '0939239', 'HINNI', 'æði', '[takn]', 'abb', 'áb', 'ma', 'æði', 'íris', 'þalli', 'hannes'].sort(islCompare()); | |
console.log(sorted); | |
// todo: maybe do something different with numbers |
This file contains 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
var order = '0123456789aAáÁbBcCdDeEéÉfFgGhHiIíÍjJkKlLmMnNoOóÓpPqQrRsStTuUúÚvVwWxXyYýÝzZþÞæÆöÖ'; | |
function charOrder(a) { | |
var ix = order.indexOf(a); | |
return ix === -1 ? a.codePointAt() + order.length : ix; | |
} | |
function customIsCollator(a, b) { | |
for (var i = 0; i < Math.min(a.length, b.length); i++) { | |
var iA = charOrder(a[i]); | |
var iB = charOrder(b[i]); | |
if (iA != iB) return iA - iB; | |
} | |
return a.length - b.length; | |
} | |
var sorted = ['ab', '0939239', 'HINNI', 'æði', '[takn]', 'abb', 'áb', 'ma', 'æði', 'íris', 'þalli', 'hannes'].sort(customIsCollator); | |
console.log(sorted); | |
// todo: maybe do something different with numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment