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}];
- Create an empty array named items.
- Create an array named allColors that contains all of the colors in the arrays named primary and secondary.
- 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.
- Use the array named all to create an array named favs which contains only the elements with indices between (inclusively) between 1 and 4.
- Modify the array named all to include the first element of all, the color “black”, followed by the last element of all.
- 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.
- Write a statement that uses find and stores in a variable named o the first object in objArray that has score greater than 20.
- 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.
- 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.
- Write a statement that sets over to true if some score in objArray is greater than 20, and sets over to false otherwise.
- Write a statement that uses map to create an array of the scores in objArray.
- 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.
- 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.