scrimba
Note at 0:58
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:58
AboutCommentsNotes
Note at 0:58
Expand for more info
main.js
run
preview
console
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"]);
});
});
Console
"result: "
,
[
"organization"
,
"commercial"
,
"network"
,
"information"
]
,
/index.html
LIVE