Skip to content

Instantly share code, notes, and snippets.

@queckezz
Created November 18, 2017 21:44
Show Gist options
  • Save queckezz/485b52d848970a83fc3b85a9ce743ed7 to your computer and use it in GitHub Desktop.
Save queckezz/485b52d848970a83fc3b85a9ce743ed7 to your computer and use it in GitHub Desktop.
sort urls alphabetically
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