diff --git a/examples/object_array/complete.html b/examples/object_array/complete.html index 13628eb..c94f461 100644 --- a/examples/object_array/complete.html +++ b/examples/object_array/complete.html @@ -25,28 +25,27 @@ // Create an array of all people who have siblings // You will need people.filter -const hasSiblings = - - - +const hasSiblings = people.filter(person => + person.siblings === true) +console.log(hasSiblings) // Create an array of all people who do NOT have pets // You will need people.filter -const noPets = - - +const noPets = people.filter(person => + person.pets === false) +console.log(noPets) // Create an array of all people who have pets but no siblings // You will need people.filter -const petsNoSiblings = - +const petsNoSiblings = people.filter(person => + person.pets === true && person.siblings === false) +console.log(petsNoSiblings) - -// Create an array that stores everyone's names in firstName,lastName format, sorted alphabetically by last name +// Create an array that stores everyone's names in lastName,firstName format, sorted alphabetically by last name // you will need people.map -const lastFirstSorted = - - +const lastFirstSorted = people.map(person => + `${person.lastName}, ${person.firstName}`).sort(); +console.log(lastFirstSorted) // Create a function that accepts two parameters - a color name and an array. // It then returns an array of all the objects where the person's favorite color matches. @@ -54,14 +53,15 @@ // You will need a function, and I have started that code for you here. Your constants will use the function. function colorMatch(color,arr) { - const matches = - + const matches = people.filter(person => + person.favoriteColor.toLowercase() === color.toLowercase()) + return(matches) } -const blueTest = - +const purpleTest = colorMatch("purple",people) +console.log(purpleTest) -const blackTest = +const lightBlueTest = diff --git a/examples/object_array/data.js b/examples/object_array/data.js index 8940c42..11da2a4 100644 --- a/examples/object_array/data.js +++ b/examples/object_array/data.js @@ -6,8 +6,8 @@ const people = [ age: 40, siblings: true, pets: true, - favoriteColor: "purple" -} + favoriteColor: "Purple" +}, { firstName: "Julia", @@ -18,7 +18,7 @@ const people = [ pets: true, favoriteColor: "purple", closeSecondFavoriteColor: "green" -} +}, { firstName: "Thomas", @@ -28,5 +28,10 @@ const people = [ siblings: true, pets: true, favoriteColor: "light-blue", -} +}, + +{ + siblings: false, + pets: true +} ]