// Using an Object literal:
function getTLD (tld) {
const tlds = {
'org': () => 'organization',
'com': () => 'commercial',
'net': () => 'network',
'info': () => 'information',
'default': () => 'unrecognised',
};
return (tlds[tld] || tlds['default'])();
}
// Using a plain Object:
// const tlds = {
// org: 'organization',
// com: 'commercial',
// net: 'network',
// info: 'information'
// }
// const domainType = ds => ds.map(d => tlds[d.split('.')[d.split('.').length - 1]])
const domainType = ds => ds.map(d => getTLD(d.split('.')[d.split('.').length - 1]))
/**
* 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"]);
});
});