Project: party guest list
JavaScript · Unit 8: More on arrays
- Full plan
- JavaScript
- Project
- 4 exercises
Ava and Leo are throwing a party, and each of them made a guest list. Some people are on both. With ... you join the lists, and with a Set you remove the repeats.
const ava = ["Emma", "Noah"];
const leo = ["Noah", "Mia"];
const all = [...ava, ...leo];
console.log(all);
console.log([...new Set(all)]);Prints
[ 'Emma', 'Noah', 'Noah', 'Mia' ] [ 'Emma', 'Noah', 'Mia' ]
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Complete the function that joins both lists without repeating anyone.
2. Multiple choice
What does
onlyhold when this code finishes?3. Write the code
Write
inCommon(a, b), which returns an array with the guests who are on both lists, in the order of lista. Neither list has repeats.4. Write the code
Write
summary(a, b), which returns an object withtotal, how many different people are coming to the party, andshared, how many are on both lists. For example, with["Ava", "Leo"]and["Leo", "Mia"]it gives{ total: 3, shared: 1 }.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.