Write a function called mergeArrays that combines two arrays into one.
mergeArrays(["Rattata", "Raticate"], ["Bulbasaur", "Ivysaur", "Venusaur"])
// returns ["Rattata", "Raticate", "Bulbasaur", "Ivysaur", "Venusaur"]
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"
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"]
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]
]
*/
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:
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!
In JS2 you learned about:
div
tag, which we use to group elements on HTML pagesinnerHTML
and innerText
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)
.