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