Skip to content

Instantly share code, notes, and snippets.

@mlimberg
Created June 5, 2017 20:15
Show Gist options
  • Save mlimberg/3b59fb7ca29b22db517778797e6ebdb1 to your computer and use it in GitHub Desktop.
Save mlimberg/3b59fb7ca29b22db517778797e6ebdb1 to your computer and use it in GitHub Desktop.

Question 1

What is the difference between var, let, and const?

Question 2

Consider the following blocks of code.

let array = [];

for (var i = 0; i < 10; i++) {
  array[i] = function () {
    console.log('You clicked: ' + i);
  };
}

array[5]() // what will log here?

let array = [];

for (let i = 0; i < 10; i++) {
  array[i] = function () {
    console.log('You clicked: ' + i);
  };
}

array[5]() // what will log here?

  • Explain what is being logged
  • Explain why it’s being logged
  • Explain the difference between block and function scope.

Question 3

What is the typeof the first parameter passed to forEach, map, find, filter, and reduce? What is this first parameter typically called?

Question 4

Explain the differences between object bracket notation and dot nation. When would brackets be better to use than dot?

Question 5

Write a function that will take this array of objects and return an object that counts up all the groceryList items

var array = [
  {
    name: 'yung-jhun',
    groceryList: [
      'grapes',
      'avocados',
      'chicken',
      'tortillas',
      'rice',
      'pop-tarts'
    ]
  },
  {
    name: 'alter-nate',
    groceryList: [
      'chips',
      'kale',
      'chicken',
      'tortillas',
      'yogurt',
      'granola'
    ]
  },
  {
    name: 'limbonator',
    groceryList: [
      'chips',
      'eggs',
      'tomatoes',
      'tortillas',
      'rice',
      'avocados',
      'pop-tarts'
    ]
  }
]


=> { 
  	grapes: 1,
  	avocados: 2,
  	chicken: 2,
  	tortillas: 3,
  	rice: 2,
  	'pop-tarts': 3,
  	tomatoes: 2,
  	chips: 2,
  	kale: 1,
  	yogurt: 1,
  	granola: 1,
  	eggs: 1 
  }

Question 6

Consider the following code.

function Hoodlum1 (name, alterEgo) {
  this.name = name;
  this.secret = {
    name: alterEgo,
    getName: function () {
      return this.name;
    }
  }
}

function Hoodlum2 (name, alterEgo) {
  this.name = name;
  this.secret = {
    name: alterEgo,
    getName: () => {
      return this.name;
    }
  }
}

Answer the following questions:

  • In Hoodlum1 when you call getName function what is being logged and why?
  • In Hoodlum2 when you call getName function what is being logged and why?
  • In Hoodlum1 how can I get the getName function to log the alterEgo value?

Question 7

Write a function that takes this large object and returns a new object with two keys yongerThan15 && olderThan15. The interaction should look like this:

var objects = {
  person1: {name: 'taylor', age: 11},
  person2: {name: 'jhun', age: 12},
  person3: {name: 'alter-nate', age: 16},
  person4: {name: 'meeka', age: 16}
}

// return an object that looks like this

{
  youngerThan15: [
    {name: 'taylor', age: 11},
    {name: 'jhun', age: 12}
  ],
  olderThan15: [
    {name: 'alter-nate', age: 16},
    {name: 'meeka', age: 16}
  ]
}

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