Finding Common Elements Between Arrays in JavaScript

preview_player
Показать описание
Finding Common Elements Between Arrays in JavaScript
JavaScript: How to Find Array Intersection
Intersecting Arrays in JavaScript
JavaScript Guide: Array Intersection
Working with Array Intersection in JavaScript
Рекомендации по теме
Комментарии
Автор

This is an unreasonably inefficient way to solve this problem it is an O(n*m) solution.

Instead what you should do is convert the shorter array into an object using each element as the key and the value then loop through the longer array and check if the value exists in the object as a key. This would be an O(n+m) which is far more efficient since you don’t loop though the first array at every itteration

smeldge
join shbcf.ru