HomeGorakh Raj Joshi

Array Intersection

Write a function called arrayIntersection that takes in two arrays and returns an array containing the intersection of the two input arrays (i.e., the common elements that appear in both arrays).

  • #Basic
function arrInt(arrOne, arrTwo) {
  const arrOneSet = new Set(arrOne);

  return arrTwo.filter((el) => arrOneSet.has(el));
}
arrInt([1, 2, 3], [2, 3, 4]);

Gorakh Raj Joshi

Senior Fullstack Engineer: Specializing in System Design and Architecture, Accessibility, and Frontend Interface Design

LinkedIn

GitHub

Email

All rights reserved © Gorakh Raj Joshi 2024