Explorer
project
boot.js
index.html
index.js
jasmine-html.js
jasmine.css
jasmine.js
main.js
Dependencies
Bootcamp
Study group
Collaborate with peers in your dedicated #study-group channel.
Code reviews
Submit projects for review using the /review
command in your #code-reviews channel
function domainType(domains) {
// Check for null & undefined
if (domains === null || domains === undefined) {
alert("Nothing comes from nothing")
return null
}
// Switch to determine domain long-form name
const elongator = (domain) => {
switch(domain) {
case "com":
return "commercial"
case "org":
return "organization"
case "biz":
return "business"
case "info":
return "information"
case "net":
return "network"
case "gov":
return "government"
case "edu":
return "education"
case "mil":
return "military"
default:
return "unknown domain"
}
}
// Process array
let results = []
domains.forEach(dom => {
let splitted = dom.split(".")
results.push(elongator(splitted[splitted.length-1]))
})
return results
}
/**
* Test Suite
*/
describe('domainType()', () => {
it('returns list of domain types', () => {
// arrange
const domains = ["en.wiki.org", "codefights.com", "happy.net", "code.info"];
// act
const result = domainType(domains);
// log
console.log("result: ", result);
// assert
expect(result).toEqual(["organization", "commercial", "network", "information"]);
});
it('returns list of domain types check #2', () => {
// arrange
const domains = ["en.wiki.biz", "codefights.edu", "happy.gov", "code.mil"];
// act
const result = domainType(domains);
// log
console.log("result: ", result);
// assert
expect(result).toEqual(["business", "education", "government", "military"]);
});
});