Created
April 22, 2017 06:06
-
-
Save milanraai/605b21b83c7285d3e7de6610971d059b to your computer and use it in GitHub Desktop.
Module 3 Assessment - Milan Rai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part 1 | |
// Write a function that takes 3 words and returns a single count of all their letters. | |
function combinedCharacterCount(word1, word2, word3) { | |
// get length of 3 words | |
// return var sumOfThreeWords | |
return word1.length + word2.length + word3.length; | |
} | |
// Part 2 | |
function assert(expectedBehavior, descriptionOfCorrectBehavior) { | |
if (!expectedBehavior) { | |
console.log(descriptionOfCorrectBehavior); | |
} else { | |
console.log('test passed'); | |
} | |
} | |
//assert(combinedCharacterCount('I', 'am', 'here') === 7, "should correctly count the total number of characters"); | |
// Part 3 | |
//Given an array of companies, return an array of all the company names founded last century | |
function collectCompaniesFoundedLastCentury(companies) { | |
// iterate through companies array; | |
// within the companies var getFoundingCentury | |
// var currentCentury = 2000 | |
// compare the currentCentury < getFoundingCentury | |
// return object of that company | |
//var result = []; | |
var currentCentury = 2000; | |
for (i = 0; i < companies.length; i++) { | |
var companyDetails = companies[i]; | |
for(var x in companyDetails) { | |
var getFoundingCentury = companyDetails.founded_year; | |
if (getFoundingCentury < currentCentury) { | |
return [companies[i]]; | |
} | |
} | |
} | |
//return result; | |
}; | |
var companies = [ | |
{ | |
"name" : "AdventNet", | |
"category_code" : "enterprise", | |
"number_of_employees" : 600, | |
"founded_year" : 1996, | |
"total_money_raised" : "$0" | |
}, | |
{ | |
"name" : "TechnologyGuide", | |
"category_code" : "web", | |
"number_of_employees" : 10, | |
"founded_year" : 2001, | |
"total_money_raised" : "$0" | |
}, | |
{ | |
"name" : "Wetpaint", | |
"category_code" : "web", | |
"number_of_employees" : 47, | |
"founded_year" : 2005, | |
"total_money_raised" : "$39.8M" | |
}, | |
{ | |
"name" : "Zoho", | |
"category_code" : "software", | |
"number_of_employees" : 1600, | |
"founded_year" : 2005, | |
"total_money_raised" : "$0" | |
}, | |
{ | |
"name" : "Omnidrive", | |
"category_code" : "network_hosting", | |
"number_of_employees" : null, | |
"founded_year" : 2005, | |
"total_money_raised" : "$800k" | |
}, | |
{ | |
"name" : "Digg", | |
"category_code" : "news", | |
"number_of_employees" : 60, | |
"founded_year" : 2004, | |
"total_money_raised" : "$45M" | |
}, | |
{ | |
"name" : "Geni", | |
"category_code" : "web", | |
"number_of_employees" : 18, | |
"founded_year" : 2006, | |
"total_money_raised" : "$16.5M" | |
}, | |
{ | |
"name" : "StumbleUpon", | |
"category_code" : "web", | |
"number_of_employees" : null, | |
"founded_year" : 2002, | |
"total_money_raised" : "$18.5M" | |
} | |
]; | |
var actual = collectCompaniesFoundedLastCentury(companies); | |
var expected = [ | |
{ | |
"name" : "AdventNet", | |
"category_code" : "enterprise", | |
"number_of_employees" : 600, | |
"founded_year" : 1996, | |
"total_money_raised" : "$0" | |
}]; | |
console.log(JSON.stringify(actual) === JSON.stringify(expected)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment