AniUI Academy
medium+250 XPPractice

Union several arrays, first appearance wins

Combining a user's saved filters with the defaults and with whatever the URL asked for gives you three arrays that overlap. You want one list, no repeats, and an order that feels stable.

Implement union(...arrays) taking any number of arrays as separate arguments. Return a single array containing every value from every input, deduplicated, in the order each value first appeared when reading the arrays left to right and each array front to back. Values are compared the way a Set compares them. Duplicates inside a single array are removed too. Empty arrays contribute nothing, and calling union() with no arguments returns an empty array. Never modify the inputs.

What it has to do

  • Accept a variable number of array arguments.
  • Include each distinct value once, at the position of its first appearance.
  • Deduplicate within a single array as well as across arrays.
  • Return [] when called with no arguments.
  • Do not mutate any input array.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.