Skip to content

Instantly share code, notes, and snippets.

@defektive
Last active February 14, 2020 12:32
Show Gist options
  • Save defektive/7a546d70452fa7771b219961f11e092b to your computer and use it in GitHub Desktop.
Save defektive/7a546d70452fa7771b219961f11e092b to your computer and use it in GitHub Desktop.
s.sort((a,b) => {
a = a.replace(/^[a-z]+:\/\//, '')
b = b.replace(/^[a-z]+:\/\//, '')
a = a.split("/")[0];
b = b.split("/")[0];
if (a.indexOf('.') === -1) return 1
if (b.indexOf('.') === -1) return -1
let aa = a.split("."),
bb = b.split("."),
m = Math.min(aa.length, bb.length),
i = 0;
while (m--) {
i++
let ap = aa[aa.length - i],
bp = bb[bb.length - i];
if (ap == bp) continue
if ([ap, bp].sort()[0] != ap) return 1
return -1
}
return 0;
}).join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment