Skip to content

Instantly share code, notes, and snippets.

@HashirHussain
Created January 4, 2024 05:44
Show Gist options
  • Save HashirHussain/87ddac328ab4269f56bed3bdc94a97e2 to your computer and use it in GitHub Desktop.
Save HashirHussain/87ddac328ab4269f56bed3bdc94a97e2 to your computer and use it in GitHub Desktop.
Write a function to parses out just the domain name and returns it as a string.
/**
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:
url = "http://github.com/carbonfive/raygun" -> domain name = "github"
url = "http://www.zombie-bites.com" -> domain name = "zombie-bites"
url = "https://www.cnet.com" -> domain name = cnet"
**/
function domainName(url) {
//your code here
}
//Test case
const { assert } = require("chai");
describe("Sample test", () => {
it("Should pass sample tests", () => {
assert.equal(domainName("http://google.com"), "google");
assert.equal(domainName("http://google.co.jp"), "google");
assert.equal(domainName("www.xakep.ru"), "xakep");
assert.equal(domainName("https://youtube.com"), "youtube");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment