Created
January 4, 2024 05:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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