scrimba
Note at 0:22
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:22
AboutCommentsNotes
Note at 0:22
Expand for more info
main.js
run
preview
console
function domainType(domains) {
// Check for null & undefined
if (domains === null || domains === undefined) {
alert("Nothing comes from nothing")
return null
}

// Switch to determine domain long-form name
const elongator = (domain) => {
switch(domain) {
case "com":
return "commercial"
case "org":
return "organization"
case "biz":
return "business"
case "info":
return "information"
case "net":
return "network"
case "gov":
return "government"
case "edu":
return "education"
case "mil":
return "military"
default:
return "unknown domain"
}
}

// Process array
let results = []

domains.forEach(dom => {
let splitted = dom.split(".")
results.push(elongator(splitted[splitted.length-1]))
})

return results
}



/**
* 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"]);
});

it('returns list of domain types check #2', () => {
// arrange
const domains = ["en.wiki.biz", "codefights.edu", "happy.gov", "code.mil"];

// act
const result = domainType(domains);

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

// assert
expect(result).toEqual(["business", "education", "government", "military"]);
});
});
Console
"result: "
,
[
"organization"
,
"commercial"
,
"network"
,
"information"
]
,
"result: "
,
[
"business"
,
"education"
,
"government"
,
"military"
]
,
/index.html
LIVE