Created
November 18, 2017 21:44
-
-
Save queckezz/485b52d848970a83fc3b85a9ce743ed7 to your computer and use it in GitHub Desktop.
sort urls alphabetically
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 sortUrls(urls) { | |
return urls | |
.map(link => { | |
const normalizedLink = /^(https?:\/\/)?(www\.)?/.exec(link)[0] | |
return [link.replace(normalizedLink, ''), normalizedLink] | |
}) | |
.sort(([a], [b]) => { | |
if(a < b) return -1 | |
if(a > b) return 1 | |
return 0 | |
}) | |
.map(([link, prefix]) => prefix + link) | |
.join('\n') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment