scrimba
Note at 0:17
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:17
AboutCommentsNotes
Note at 0:17
Expand for more info
main.js
run
preview
console
function domainType(domains) {
let result = []
const domainMap = {
"org" : "organization",
"com" : "commercial",
"net" : "network",
"info" : "information"
}

for (let i=0; i< domains.length; i++) {
const splitDomain = domains[i].split(".")
const lastElement = splitDomain[splitDomain.length-1]
result[i] = domainMap[lastElement]
// console.log(result)
// result.push(domainMap[lastElement])
}
return result
}

/*or:

function domainType(domains) {
let result = []
const org = "organization"
const com = "commercial"
const net = "network"
const info = "information"

for (let i=0; i< domains.length; i++) {
const domain = domains[i]
const splitDomain = domain.split(".")
const lastElement = splitDomain[splitDomain.length-1]

if (lastElement.includes("org")) {
result.push(org)
} else if (lastElement.includes("com")) {
result.push(com)
} else if (lastElement.includes("net")) {
result.push(net)
} else if (lastElement.includes("info")) {
result.push(info)
}
}
return result
}

or:

function domainType(domains) {
let result = []
let org = "organization"
let com = "commercial"
let net = "network"
let info = "information"

for (let i=0; i< domains.length; i++) {
let domain = domains[i]
if (domain.includes("org")) {
result.push(org)
} else if (domain.includes("com")) {
result.push(com)
} else if (domain.includes("net")) {
result.push(net)
} else if (domain.includes("info")) {
result.push(info)
}
}
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"]);
});
});
Console
"result: "
,
/index.html
LIVE