function domainType(domains) {
domainTypes = [];
for (domain of domains) {
switch (domain[domain.length - 1].toLowerCase()) {
case 'g':
domainTypes.push('organization');
break;
case 'm':
domainTypes.push('commercial');
break;
case 't':
domainTypes.push('network');
break;
case 'o':
domainTypes.push('information');
break;
default:
throw 'invalid domain'
}
}
return domainTypes;
}
/**
* 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"]);
});
});