Chapter 6 Part II Review

For the following problems assume you have the following arrays.

 
let primary = ["red", "blue", "yellow"];  
let secondary = ["green", "purple", "orange"];
let all = ["red", "blue", "yellow", "green", "purple", "orange"];
let objArray = [{name: "joe", score: 21}, {name: "shea", score: 22}, {name: "al", score: 19}];
  1. Create an empty array named items.
  2. Create an array named allColors that contains all of the colors in the arrays named primary and secondary.
  3. Create an array named colorSets that contains 2 elements. The first element being the array named primary and the second element being the array named secondary.
  4. Use the array named all to create an array named favs which contains only the elements with indices between (inclusively) between 1 and 4.
  5. Modify the array named all to include the first element of all, the color “black”, followed by the last element of all.
  6. Write a statement that creates a variable named idx and sets it equal to index of the first occurrence of the string “black” in an array named all.
  7. Write a statement that uses find and stores in a variable named o the first object in objArray that has score greater than 20.
  8. Write a statement that uses filter to create an array named winners that contains all of the objects in objArray that have scores greater than 20.
  9. Write a statement that creates a variable named over and sets it to true if every score in objArray is greater than 20, and sets over to false otherwise.
  10. Write a statement that sets over to true if some score in objArray is greater than 20, and sets over to false otherwise.
  11. Write a statement that uses map to create an array of the scores in objArray.
  12. Write a statement that uses forEach to print to the console the names in objArray that are associated with scores that are greater than 20.
  13. Write a statement that uses reduce to compute the largest score in the array named objArray and stores the value in a variable named max.

© 2020, Eric. All rights reserved.