← Back to challenges

Learn Lodash (1): Intersection of Arrays

JavaScriptHardarrays

Instructions

Write a function that creates an array of values found within all given arrays. The first array will serve as the base from which the remaining arrays will be checked to see if they have the matching values. If they do they will be added to the new array which will return only unique values showing the "intersecting" values of all arrays.

The actual intersection lodash function uses "Same Value Zero" comparison which means that it only works on strings and numbers. To make this challenge more difficult I've included objects to help you determine how to compare them.

Examples

intersection([1, 2, 3], [3, 4, 5], [2, 9, 9]) ➞ [2, 3]
// Both 2 and 3 are in the first array and can also be found in the others.

Notes

  • Do not attempt to import lodash; you are simply writing your own version.
  • This entire series of challenges can be found here.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.