Preflight

  1. Write a function called mergeArrays that combines two arrays into one.

    mergeArrays(["Rattata", "Raticate"], ["Bulbasaur", "Ivysaur", "Venusaur"])
    // returns ["Rattata", "Raticate", "Bulbasaur", "Ivysaur", "Venusaur"]
    
  2. Write a function called firstLongerThan that finds the first string in an array longer than the given number.

    firstLongerThan(["Ekans", "Arbok", "Pikachu", "Raichu"], 5) // returns "Pikachu"
    
  3. Write a function called getReturnValues that takes in an array of functions, and returns an array of values returned by the functions.

    getReturnValues( [
      () => {
        return 25
      }, 
      () => {
        return 29
      }, 
      () => {
        return "Pikachu"
      }
    ]) // returns [25, 29, "Pikachu"]
    
  4. Write a function called zeroSquare that takes in a number, and returns a square two-dimensional array with the input number rows and columns filled with zeros.

    zeroSquare(1) // returns [[0]]
    zeroSquare(2) // returns [[0,0], [0,0]]
    /*
    [
      [0,0],
      [0,0]
    ]
    */
    
    zeroSquare(3) // returns [[0,0,0], [0,0,0], [0,0,0]]
    /*
    [
      [0,0,0],
      [0,0,0],
      [0,0,0]
    ]
    */
    

Overview

In the last lesson, you familiarized yourself with HTML, then learned all about arrays. You'll want to have all the array functions at your disposal for this lesson, so go back and make sure you've memorized them before going forward!

If you have any issues solving any of the Preflight questions, please review the questions and solutions. This lesson will rely heavily on the foundations covered in the previous lesson in three parts:

  1. The first part will build on your existing HTML knowledge and introduce you to a couple more element properties.
  2. The second part will teach you what you need to know about objects, a powerful non-primitive data type in JavaScript.
  3. The third part will introduce you to libraries and APIs.

Objects are the last, but most important, data type we'll learn in JavaScript. If the concept is new to you, remember to review frequently. After this lesson, you will have learned everything you need to solve the algorithm section of a coding interview and can start practicing the problems on leetCode. Make sure to follow the 5 steps for each problem!

HTML

In JS2 you learned about:

In the last lesson you learned about setting an element's onclick attribute to assign a function to run when the user clicks on the element. A downside to this method is that you can only assign one function to each element. Best practice is to run the element's addEventListener function:

addEventListener('eventName', function).