-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuntober-oct12.js
More file actions
30 lines (19 loc) · 1.08 KB
/
Copy pathhuntober-oct12.js
File metadata and controls
30 lines (19 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Make sure you understand these before taking a look at the question:
// Replace (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
// Split (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
// 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("http://github.com/carbonfive/raygun") == "github"
// domainName("http://www.zombie-bites.com") == "zombie-bites"
// domainName("https://www.cnet.com") == "cnet
function domainName(str){
let arr = str.replace('www.', '').split('//')
let url = arr.filter(item => !item.includes(':') )
return url.join("").split(".")[0]
}
console.log(domainName("http://github.com/carbonfive/raygun"))
console.log(domainName("http://www.zombie-bites.com"))
console.log(domainName("https://www.cnet.com"))
console.log(domainName("http://google.com"))
console.log(domainName("https://youtube.com"))
console.log(domainName("http://google.co.jp"))
console.log(domainName("www.xakep.ru"))