Created
November 26, 2023 12:44
-
-
Save nexpr/fdb7c976d9b90ebb894a5df839725ada to your computer and use it in GitHub Desktop.
sort domain
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
export const sortDomain = (domains) => { | |
return domains.map(x => x.split(".")).sort((a, b) => { | |
const max = Math.max(a.length, b.length) | |
const recur = (i = 0) => { | |
if (i >= max) return 0 | |
return (a.at(-i - 1) ?? "").localeCompare(b.at(-i - 1) ?? "") || recur(i + 1) | |
} | |
return recur() | |
}).map(x => x.join(".")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment