Skip to the content

Project: party guest list

JavaScript · Unit 8: More on arrays

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. 1. Complete the code

    Complete the function that joins both lists without repeating anyone.

  2. 2. Multiple choice

    What does only hold when this code finishes?

  3. 3. Write the code

    Write inCommon(a, b), which returns an array with the guests who are on both lists, in the order of list a. Neither list has repeats.

  4. 4. Write the code

    Write summary(a, b), which returns an object with total, how many different people are coming to the party, and shared, how many are on both lists. For example, with ["Ava", "Leo"] and ["Leo", "Mia"] it gives { total: 3, shared: 1 }.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →