FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Intersection By

20mins

Implement a function intersectionBy(arrays, iteratee) that computes the intersection of multiple arrays, returning only the unique values that are present in all arrays. The comparison should be based on a provided iteratee function.

The function should:

  • Accept an array of arrays.
  • Accept an iteratee function that transforms values for comparison.
  • Return an array of unique values present in all arrays, using the iteratee to determine equality.

Example

intersectionBy([[2.1, 1.2], [2.3, 3.4]], Math.floor); // [2] intersectionBy([[{x:1},{x:2}], [{x:2},{x:3}]], o => o.x); // [{x:2}]

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests