-
Notifications
You must be signed in to change notification settings - Fork 0
/
replaceDomain.js
22 lines (17 loc) · 908 Bytes
/
replaceDomain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example:
// domainName("https://github.com/carbonfive/raygun") == "github"
// domainName("https://www.zombie-bites.com") == "zombie-bites"
// domainName("https://www.cnet.com") == "cnet
//given url -> domain-name
// domainName("https://github.com/carbonfive/raygun") == "github"
// domainName("https://www.zombie-bites.com") == "zombie-bites"
// domainName("https://www.cnet.com") == "cnet
//replace parts of url u don't want 'https://', 'https://', 'www.'
//split '.'
function replaceDomain(str) {
let result = str.replace("https://",'').replace("https://",'').replace("www.", '').split('.')
return result[0]
}
console.log(replaceDomain("https://github.com/carbonfive/raygun"))
console.log(replaceDomain("https://www.zombie-bites.com"))
console.log(replaceDomain("https://www.cnet.com"))