function domainType(domains) {
// write code here.
let domainArr = [];
for(let i = 0; i < domains.length; i++) {
let nameBreakdown = domains[i].split('.'); //breaks down domain name to array strings
let domainType = nameBreakdown[nameBreakdown.length - 1]; //domain type is last so i can
select this last string.
// this solution may still need refinement as subdirectory items would break it as is. the
if statment searches for the domain and assigns it the new strin name before adding it to
our Domain Array
if(domainType === 'org') {
domainArr.push("organization");
} else if(domainType === 'com') {
domainArr.push("commercial");
} else if(domainType === 'net') {
domainArr.push("network");
} else if(domainType === 'info') {
domainArr.push("information");
}
}
return domainArr;
}
/**
* 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"]);
});
});