Review of Week 2 Day 2 Learning Objectives

POJOs

1. Label variables as either Primitive vs. Reference

Javascript considers most data types to be ‘primitive’, these data types are immutable, and are passed by value. The more complex data types: Array and Object are mutable, are considered ‘reference’ data types, and are passed by reference.

2. Identify when to use . vs [] when accessing values of an object

let obj = { "one": 1, "two": 2 };

// Choose the square brackets property accessor when the property name is determined at
// runtime, or if the property name is not a valid identifier
let myKey = "one";
console.log(obj[myKey]);

// Choose the dot property accessor when the property name is known ahead of time.
console.log(obj.two);

3. Write an object literal with a variable key using interpolation

let keyName = "two";

// If the key is not known, you can use an alternative `[]` syntax for
// object initialization only
let obj2 = { [keyName]: 2 }
console.log(obj2);

4. Use the obj[key] !== undefined pattern to check if a given variable that contains a key exists in an object

function doesKeyExist(obj, key) {
  // obj[key] !== undefined
  // or:
  return key in obj;
}

let course = { bootcamp: 'App Academy', course: 'Bootcamp Prep' }
console.log(doesKeyExist(course, 'course')); // => true
console.log(doesKeyExist(course, 'name')); // => false

5. Utilize Object.keys and Object.values in a function

function printKeys(object) {
  return Object.keys(object);
}

function printValues(object) {
  return Object.values(object);
}

console.log(printKeys({ dog: "Strelka", dog2: "Belka" }));
console.log(printValues({ dog: "Strelka", dog2: "Belka" }));

6. Iterate through an object using a for in loop

let player = { name: "Sergey", skill: "hockey" };

for (let key in player) {
   console.log(key, player[key]);
}

console.log(Object.entries(player));

7. Define a function that utilizes …rest syntax to accept an arbitrary number of arguments

function restSum(...otherNums) {
  let sum = 0;
  console.log(otherNums);
  otherNums.forEach(function (num) {
    sum += num;
  });

  return sum;
}

console.log(restSum(3, 5, 6)); // => 14
console.log(restSum(1, 2, 3, 4, 5, 6, 7, 8, 9)); // => 45
console.log(restSum(0)); // => 0

8. Use …spread syntax for Object literals and Array literals

let numArray = [1, 2, 3];
let moreNums = [...numArray, 4, 5, 6]

console.log(moreNums);

let shoe = { color: "red", size: 10 };
let newShoe = { ...shoe, brand: "Nike", size: 12 };
console.log(newShoe);
newShoe.color = "black";
console.log(newShoe);

console.log(shoe);

9. Destructure an array to reference specific elements

let arr = ['one', 'two', 'three'];

let [first] = arr;
console.log(first);

10. Destructure an object to reference specific values

let me = {
    name: "Ian",
    instruments: ['bass', 'synth', 'guitar'],
    siblings: {
        brothers: ['Alistair'],
        sisters: ['Meghan']
    }
}

let { name, instruments: musical_instruments, siblings: {sisters}} = me;

console.log(name);
console.log(musical_instruments);
console.log(sisters);

11. Write a function that accepts a string as an argument and returns an object representing the count of each character in the array

function charCount(inputString) {

    let res = inputString.split("").reduce(function(accum, el) {
        if (el in accum) {
            accum[el] = accum[el] + 1;
        } else {
            accum[el] = 1;
        }
        return accum;
    }, {})
    return res;

}

console.log(charCount('aaabbbeebbcdkjfalksdfjlkasdfasdfiiidkkdingds'));

Pair Programming

1. Differentiate between the “Driver” and “Navigator” roles in a pair programming session.

Driver - has complete control of the keyboard and mouse, little or no input on the code output on the screen

Navigator - has no control of the keyboard and mouse, has majority or all input on the code that is output on the screen

2. Describe at least three benefits of effective pair programming.

3. Demonstrate empathetic communication and be able to explain the meaning of “You are not your code”.

Empathetic communication is communication that takes into account what we do, the way we do it, and our impact on other people. As this awareness grows, we create better connections more quickly and find ourselves more motivated and willing to respond in any situation.

“You are not your code” - You may be an excellent programmer. But do people want to work with you? You may write bad code and still be an awesome person. People will gravitate towards those with excellent communication skills. Maintaining a positive and friendly attitude will lead to better collaboration and long term connections.

4. Identify negative interactions during a pair programming session.

5. Identify the exact steps of a/A’s pair programming process.

Note: If you are both stuck and need a few extra minutes to talk about implementation, pause the timer, talk it through, and then start again!

6. Describe the importance of pair programming competency while interviewing for jobs.

In a technical interview, you’re going to have to explain your thought process when solving an algorithm or talking about system design. Getting the correct answer to the algorithm isn’t always what the interviewer is looking for. The question may be very abstract and your line of questioning/communicating might be what pushes you to the next round of interviews. Having excellent verbal and interpersonal skills will have the interviewer rooting for you to succeed.