EkaterinaRomankova / Codewars

Codewars
0 stars 0 forks source link

Extract the domain name from a URL #45

Open EkaterinaRomankova opened 2 years ago

EkaterinaRomankova commented 2 years ago

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:

function domainName(url){ let str = url.split("/") if (str[0].includes("http")) { str = str[2] } else { str = str[0] } str = str.split('.') if (str[0] === "www") { str = str[1] } else { str = str[0] } return str }