scrimba
Note at 0:40
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:40
AboutCommentsNotes
Note at 0:40
Expand for more info
main.js
run
preview
console
// Using an Object literal:
function getTLD (tld) {
const tlds = {
'org': () => 'organization',
'com': () => 'commercial',
'net': () => 'network',
'info': () => 'information',
'default': () => 'unrecognised',
};
return (tlds[tld] || tlds['default'])();
}

// Using a plain Object:
// const tlds = {
// org: 'organization',
// com: 'commercial',
// net: 'network',
// info: 'information'
// }
// const domainType = ds => ds.map(d => tlds[d.split('.')[d.split('.').length - 1]])

const domainType = ds => ds.map(d => getTLD(d.split('.')[d.split('.').length - 1]))




/**
* 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