FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Intersection With

20mins

Implement a function intersectionWith(arrays, comparator) that returns an array of elements that exist in all input arrays, using a custom comparator function to determine equality.

The function should:

  • Accept an array of arrays.
  • Accept a comparator function (a, b) => boolean to compare elements.
  • Return an array of elements present in all arrays according to the comparator.
  • Ensure the returned array contains unique elements.

Example

intersectionWith([[1,2,3],[2,3,4]], (a,b)=>a===b); // [2,3] intersectionWith([[{x:1},{x:2}],[{x:2},{x:3}]], (a,b)=>a.x===b.x); // [{x:2}]

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests