Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

@santi100/array-intersection

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@santi100/array-intersection

Santi's Array Intersection Library: Set theory applied!

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

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:

  • 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.

  • 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.

  • 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.

  • 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.

  • 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.

  • 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.

    NameTypeDescriptionOptional?Default
    arr1T[]The first array from which to generate an intersection with arr2.NoN/A
    arr2T[]The first array from which to generate an intersection with arr1.NoN/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.

    NameTypeDescriptionOptional?Default
    arr1T[]The first array from which to generate an intersection with arr2.NoN/A
    arr2T[]The first array from which to generate an intersection with arr1.NoN/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.

Keywords

array-intersection

FAQs

Package last updated on 18 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts