function domainType(domains) {
const myRegex = /.*\.(\w+)/;
let types = [];
for (let i = 0; i < domains.length ; i++) {
let extension = domains[i].match(myRegex);
switch (extension[1]) {
case 'org':
return types.push("organization");
case 'com':
return types.push("commercial");
case 'net':
return types.push("network");
case 'info':
return types.push("information");
default:
return false;
}
}
return types;
}
/**
* 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"]);
});
});