scrimba
Note at 0:01
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:01
AboutCommentsNotes
Note at 0:01
Expand for more info
main.js
run
preview
console
function domainType(domains) {
// Iterate over each domain name in array and get top-level domain
topLevelDomains = [];

for (let domain of domains){
let domainSplit = domain.split('.');
// Push last element in each domainSplit array to topLevelDomains
for (let element of domainSplit){
if (element == domainSplit[domainSplit.length - 1]){
topLevelDomains.push(element);
}
}
}

// Iterate over topLevelDomains and assign appropriate labels
let labels = [];

for (let domain of topLevelDomains){
switch(domain){
case "org":
labels.push("organization");
break;

case "com":
labels.push("commercial");
break;

case "net":
labels.push("network");
break;

case "info":
labels.push("information");
break;
}
}
return labels;
}

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