function domainType(domains) {
//initialize a return value
const domainTypes = [];
//setup some maps of values to lookup on, maybe there is some service to get this already...
const domainsMap = {'org':'organization', 'com':'commercial', 'net':'network', 'info':
'information', 'gov':'governement','edu':'eductaion'};
//go through each domain in the domains array and examine it
domains.forEach(function(domain) {
//split a domain on the '.' to get its parts
domainParts = domain.split('.');
//use the last item in the list of domain parts and look up its value in the domains map
//push it into the domainTypes array to be returned.
domainTypes.push(domainsMap[domainParts[domainParts.length-1]]);
})
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"]);
});
});