Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions examples/object_array/complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,43 @@

// 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.
// If there are no matches, have it return "There are no matches."
// 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 =


</script>
Expand Down
13 changes: 9 additions & 4 deletions examples/object_array/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const people = [
age: 40,
siblings: true,
pets: true,
favoriteColor: "purple"
}
favoriteColor: "Purple"
},

{
firstName: "Julia",
Expand All @@ -18,7 +18,7 @@ const people = [
pets: true,
favoriteColor: "purple",
closeSecondFavoriteColor: "green"
}
},

{
firstName: "Thomas",
Expand All @@ -28,5 +28,10 @@ const people = [
siblings: true,
pets: true,
favoriteColor: "light-blue",
}
},

{
siblings: false,
pets: true
}
]