npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@santi100/array-intersection

v0.0.1

Published

Santi's Array Intersection Library: Set theory applied!

Downloads

21

Readme

Santi's Array Intersection Library

Build Status npm homepage GitHub stars License Bundlephobia stats

  • 🚀 Lightweight and fast^
  • 👴 ES3-compliant*
  • 💻 Portable between the browser and Node.js

What's this?

This is a fast, lightweight library for doing intersection of arrays, a common requirement in things like:

  1. Data Analysis: When working with datasets, finding the intersection of arrays can help identify common elements or patterns across different datasets. For example, you might want to determine the common set of customers who appear in both sales and marketing databases.

  2. Database Queries: In database management systems, intersection operations can be used to retrieve records that satisfy multiple conditions. For instance, you can find the intersection of results from different database queries to obtain a combined set of matching records.

  3. Social Networks: In social network analysis, the intersection of arrays can be employed to discover mutual connections or shared interests between individuals. It can assist in identifying common friends, followers, or communities within a social network.

  4. Set Operations: The intersection of arrays is a fundamental operation in set theory. It helps define relationships between different sets and allows for operations like finding common elements, calculating overlaps, or determining shared characteristics.

  5. Collaborative Filtering: In recommendation systems, the intersection of arrays can be used to find similar items or preferences among users. By identifying shared interests or overlapping preferences, collaborative filtering algorithms can provide personalized recommendations based on the intersection of users' preferences.

  6. Genetic Research: In genetics, the intersection of genetic profiles or DNA sequences can be employed to identify shared genetic markers or regions among individuals or populations. This information can be useful in studying genetic traits, inheritance patterns, or evolutionary relationships.

These are just a few examples!

Installation

  • Via NPM: npm install @santi100/array-intersection
  • Via Yarn: yarn add @santi100/array-intersection
  • Via PNPM: pnpm install @santi100/array-intersection

API

  • function arrayIntersection<T = unknown>(arr1: T[], arr2: T[]): T[]; Finds all common items between two arrays. | Name | Type | Description | Optional? | Default | |------------|-------------|---------------------------------------------------------------------|-----------|---------| | arr1 | T[] | The first array from which to generate an intersection with arr2. | No | N/A | | arr2 | T[] | The first array from which to generate an intersection with arr1. | No | N/A |

    Returns an array containing all items shared by both arrays.

  • function deepArrayIntersection<T = unknown>(arr1: T[], arr2: T[]): T[]; Finds all deeply common items between two arrays. Deep equality is powered by @santi100/equal-lib.

    | Name | Type | Description | Optional? | Default | |------------|-------------|---------------------------------------------------------------------|-----------|---------| | arr1 | T[] | The first array from which to generate an intersection with arr2. | No | N/A | | arr2 | T[] | The first array from which to generate an intersection with arr1. | No | N/A |

    Returns an array containing all items shared by both arrays.

Usage


import { arrayIntersection, deepArrayIntersection } from '@santi100/array-intersection'; // ESM
const { arrayIntersection, deepArrayIntersection } = require('@santi100/array-intersection'); // CJS

// Usage of arrayIntersection

const array1 = ['Alice', 'Bob', 'Charles'];
const array2 = ['Dan', 'Ethan', 'Bob', 'Alice'];

const intersection = arrayIntersection(array1, array2); // => ['Alice', 'Bob']

// Usage of deepArrayIntersection

const array3 = [{ foo: 1 }, { bar: 2 }, { baz: 3 }];
const array4 = [{ bar: 2 }, { baz: 3 }, { qux: 4 }];

const objectIntersection = deepArrayIntersection(array3, array4); // => [{ bar: 2 }, { baz: 3 }]

Contribute

Wanna contribute? File an issue or pull request! Look at the contribution instructions and make sure you follow the contribution Code of Conduct.

Disclaimers

*Hasn't been tested in an actual ES3 environment. Feel free to open an issue or pull request if you find any non-ES3 thing. See "Contribute" for instructions on how to do so.

^The source code is just a few kilobytes in size.