where on earth did s come from?
This comment is hidden because it contains spoiler information about the solution
I think I misunderstand something. For me it was not possible to distinguish between subdomain and SLD, without importing a list (I took the one from publicsuffix.org).
But I can see now the only subdomain is www., which makes the exercice quite easier :-).
OK more people pointed this out.
My code fails seven test cases but if I check those fail cases in my console I get the correct expected answer. Is it possible for someone to review my code or am I probably just wrong in my code?please advise?
My solution is not passing all test cases. For example, I get '' should equal '123'
What does that even mean? This is not explained at all in the description. If it told me what the expected output should be for all inputs I would add that to my function, but it's not written anywhere.
I agree, this is not a good question right now. Without a given list of second level domains it is not possible to extract the "domain" (which is also not the correct name as pointed out by others). For example: www.museum.tt should return "www", because "mesuem.tt" is actually a SLD that can be registered (same as .co.uk). There is a npm packages that solves this problem:
As mentioned it contains a complete list of all registerable SLD's.
Agree. After failing the .co.jp sample test case I started wondering what is actually the 'domain' of a url, if not the first subdomain under the TLD? I figured there was no way I could find it from a url -- if I had used my brains a bit more I could have come up with .co.uk and maybe .co.au, but not .co.jp, and I have know idea how many of those suffixes I am unaware of...
Since I am not a pro by a long shot, I forfeited and checked the highest ranked answers, and I see that they fail for most other cases that I had covered (ftp://, subdomains, www.org).
I don't want to say Bad kata, because it did help me learn a lot, but it can certainly be improved.
Exactly! I was only thinking about subdomain when answerin this kata & even that is enough to disqualify the "best practice" given :(
Bad kata because conditions are specified unclear, and 'domain' term is specified incorrectly.
And actually there are no valid solution without using a big database of public suffix list.
Are somebody can say before googling, if alt.za, of.by, and pvt.ge are regular domains, or subdomains of alt.za, of.by, and pvt.ge are sold to an unlimited number of people by the registrars? In this, and thousands of similar cases, should we detect "alt" as domain or no?
you are trying to split a variable that is undefined or is == ''.
you have to handle those cases before you try to split or you will get that error.
If you need to do something similar in real life it will be much simpler and effective to maintain an updated list of TLDs in your app. This kata is a good example of being asked for a quick fix to a problem that would be better served with other techniques in the long term.
This question omits the possibility that the domain name may not be the first thing you encounter after a possible "www." or "https?://". For example, a possible domain name could have been https://forum.dingdong.com. I am not sure what kind of a regex could catch it.