Skip to content

Instantly share code, notes, and snippets.

@mmeigooni
Created April 20, 2017 22:55
Show Gist options
  • Save mmeigooni/51cc584ea10a0305a8e0c7de1fae4fbb to your computer and use it in GitHub Desktop.
Save mmeigooni/51cc584ea10a0305a8e0c7de1fae4fbb to your computer and use it in GitHub Desktop.

Module 3 Assessment

This assessment is a recorded assessment. Before you start, please remember to start recording your screen. Please only submit your video and gist once you have completely finished your solutions!

Time limit: 1 hour

Part 1

Write a function that takes 3 words and returns a single count of all their letters.

function combinedCharacterCount(salesTeam) {
// your solution here
}

Part 2

Below is a simple assert function and its invocation. Add this to your code and make sure that the test passes.

Note: This is a slightly different assert than what you are used to. Take a moment to look at its declaration and invocation in order to identify how it's different to what you've seen in the past.

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

For this part, let’s pretend you’re working for a venture capital company interested in analyzing some data we have about startup companies. You’ve been given a small subset of this data to begin working with. Take a moment to look over how the data is structured:

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

Given an array of companies, return an array of all the company names founded last century

var collectCompaniesFoundedLastCentury = function (companies) {

};

Part 4

Use the assert function provided in Part 2 to write a single meaningful test for collectCompaniesFoundedLastCentury, using companies as the input.

Note: You will either need to use JSON.stringify(); or the below areArraysEqual function in order to test array/object equality.

function areArraysEqual(array1, array2) {
  var areEqual = true;
  for (var i = 0; i < array1.length; i++) {
    if (array1[i] !== array2[i]) {
      areEqual = false;
    }
  }
  return areEqual && array1.length === array2.length;
}

Part 5

Given an array of companies, return an array of all the company names that raised 20 million dollars or more. Start this problem by writing a single failing assert function before filling out the logic in the function body.

var collectTwentyMillionDollarCompanies = function (companies) {

};

Submitting your work

Please upload the video of your assessment to YouTube as an unlisted video (instructions). Once you do so, submit a link to the video and a gist of your code in this form.

Thank you!

@milanraai
Copy link

// 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));

youtube link : https://www.youtube.com/watch?v=D--OJe837E4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment