FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Intersection

10mins

Implement a function intersection(...arrays) that computes the intersection of arrays, returning a new array containing unique values present in all given arrays.

The function should:

  • Accept two or more arrays.
  • Return only the values that appear in all arrays.
  • Ensure the returned array contains only unique values.
  • Return an empty array if there is no intersection.

Examples

intersection([1, 2, 3], [2, 3, 4]); // [2, 3] intersection([1, 2, 3], [2, 3, 4], [3]); // [3] intersection([1, 2], [3, 4]); // [] intersection([], [1, 2, 3]); // [] intersection([1, 2, 2, 3], [2, 2, 3, 4]); // [2, 3]

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests