scrimba
Note at 0:56
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:56
AboutCommentsNotes
Note at 0:56
Expand for more info
main.js
run
preview
console
function domainType(domains) {
return domains.map((str) => {
if (/\.org($|\/)/.test(str)) return 'organization';
if (/\.com($|\/)/.test(str)) return 'commercial';
if (/\.net($|\/)/.test(str)) return 'network';
if (/\.info($|\/)/.test(str)) return 'information';
if (/\.de($|\/)/.test(str)) return 'germany';
if (/\.ch($|\/)/.test(str)) return 'switzerland';
if (/\.co\.uk($|\/)/.test(str)) return 'united kingdom commercial';
if (/\.uk($|\/)/.test(str)) return 'united kingdom';
//todo: add more tld
return 'unkown or invalid domain';
});
}



/**
* Test Suite
*/
describe('domainType()', () => {
it('returns list of domain types', () => {
// arrange
const domains = ["en.wiki.org", "codefights.com", "happy.net", "code.info", "theregister.co.uk", "gov.uk", "republik.ch", "aaronkessler.de"];

// act
const result = domainType(domains);

// log
console.log("result: ", result);

// assert
expect(result).toEqual(["organization", "commercial", "network", "information", "united kingdom commercial", "united kingdom", "switzerland", "germany" ]);
});
});
Console
"result: "
,
[
"organization"
,
"commercial"
,
"network"
,
"information"
,
"united kingdom commercial"
,
"united kingdom"
,
"switzerland"
,
"germany"
]
,
/index.html
LIVE