2019-03-07 Daily Challenge
What I've done today is Extract the domain name from a URL in JavaScript.
Problem is misleading and description is like shit. Data is poor.
CodeWars
Problem
Extract the domain name from a URL
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"
Solution
function domainName(url){
let s = url.replace(/https?:\/\//, "").split("/")[0];
s = s.split(".");
if (s.length > 2 && s[s.length-2] == "co") return s[s.length-3];
else return s[s.length-2];
}
In fact subdomain does not need to be "www", so...
Shit problem
{% asset_img 1.png %}