function domainType(domains) { // write code here. let result = [] for(let i=0; i<domains.length; i++){ domain_typ...
function domainType(domains) {
// write code here.
let result = []
for(let i=0; i<domains.length; i++){
domain_type = (domains[i].split('.')).slice(-1)[0]
if (domain_type == "org"){
result.push("organization")
}
else if (domain_type == "com"){
result.push("commercial")
}
else if (domain_type == "net"){
result.push("network")
}
else if (domain_type == "info"){
result.push("information")
}
else{
console.log("Invalid domain name...")
}
}
return result
}
/**
* 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"]);
});
});
COMMENTS