{"id":17930521,"url":"https://github.com/lovasoa/fast_array_intersect","last_synced_at":"2025-05-12T05:59:14.441Z","repository":{"id":35094256,"uuid":"205830510","full_name":"lovasoa/fast_array_intersect","owner":"lovasoa","description":"The fastest javascript array intersection function","archived":false,"fork":false,"pushed_at":"2024-04-30T08:37:21.000Z","size":36,"stargazers_count":24,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-12T05:58:45.110Z","etag":null,"topics":["algorithms","arrays","intersection","javascript-library","set","utility"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fast_array_intersect","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovasoa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-02T10:13:25.000Z","updated_at":"2024-08-12T19:26:04.000Z","dependencies_parsed_at":"2024-06-18T17:12:34.904Z","dependency_job_id":null,"html_url":"https://github.com/lovasoa/fast_array_intersect","commit_stats":{"total_commits":33,"total_committers":4,"mean_commits":8.25,"dds":"0.48484848484848486","last_synced_commit":"4abccc64719b639849e6e5d87c2b6a1f5b9f38b3"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Ffast_array_intersect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Ffast_array_intersect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Ffast_array_intersect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Ffast_array_intersect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovasoa","download_url":"https://codeload.github.com/lovasoa/fast_array_intersect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253685216,"owners_count":21947306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","arrays","intersection","javascript-library","set","utility"],"created_at":"2024-10-28T21:13:57.255Z","updated_at":"2025-05-12T05:59:14.374Z","avatar_url":"https://github.com/lovasoa.png","language":"JavaScript","readme":"# fast_array_intersect\n\nThe fastest javascript array intersection function.\nIt takes arrays, and returns the elements that are common to all the arrays.\nAnd it does that faster than any other published alternative I am aware of.\n\n[![npm version](https://badgen.net/npm/v/fast_array_intersect)](https://www.npmjs.com/package/fast_array_intersect)\n[![size](https://badgen.net/bundlephobia/minzip/fast_array_intersect)](https://bundlephobia.com/result?p=fast_array_intersect)\n![CI status](https://github.com/lovasoa/fast_array_intersect/workflows/Node%20CI/badge.svg)\n![Typed with TypeScript](https://badgen.net/badge/icon/Typed?icon=typescript\u0026label\u0026labelColor=blue\u0026color=555555)\n\n## How to use\n\nThis module exports a single default function, with the following signature:\n\n```js\nintersect(arrays [, hash])\n```\n\nThe arguments are :\n\n\\#| name     | optional? | type            | description\n--|----------|-----------|-----------------|---------------------------\n1 | `arrays` | required  | array of arrays | The arrays to intersect\n2 | `hash`   | optional  | function        | A function that takes an element of one of the arrays and returns a value. The value should be the same for semantically identical values.\n\nBy default, the intersection is computed for values that are equal under [*SameValueZero*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness).\nYou can use the optional hash function argument when you are intersecting arrays of javascript objects. You should then implement a function that returns the same primitive value when called with identical objects.\n\nThe order and references of result values are determined by the shortest of the input arrays.\n\n### Examples\n\n```js\nimport intersect from 'fast_array_intersect'\n\nintersect([\n  [1,2,3],\n  [1,2,6]\n]) // --\u003e [1,2]\n\nintersect([\n  [{x:2}, {y:2}],\n  [{x:1}, {x:2}]\n], JSON.stringify) // --\u003e [{x:2}]\n\nintersect([\n  [{id:0, excluded:\"A\"}, {id:1, excluded:\"B\"}],\n  [{id:0, excluded:\"C\"}, {id:2, excluded:\"C\"}]\n], x =\u003e x.id) // --\u003e [{id:0, excluded:\"A\"}]\n```\n\nWithout the ES6 import syntax, the function can be imported using : \n```js\nvar intersect = require(\"fast_array_intersect\").default;\n```\n\n## Performance\n`fast_array_intersect` is designed to be fast, and beats all other array intersection function I tested.\n\n### Benchmark\nHere is a comparison of **`fast_array_intersect`** with\n[intersect](https://www.npmjs.com/package/intersect),\n[intersection-of](https://www.npmjs.com/package/intersection-of) and\n[array-intersection-x](https://www.npmjs.com/package/array-intersection-x):\n\n```\n2 arrays of 10 elements, with an intersection of size 5...\nfast_array_intersect x 1,064,622 ops/sec ±0.55% (92 runs sampled)\nintersect x 360,324 ops/sec ±0.46% (95 runs sampled)\nintersection-of x 303,913 ops/sec ±0.35% (97 runs sampled)\narray-intersection-x x 28,616 ops/sec ±0.20% (94 runs sampled)\nFastest is fast_array_intersect\n\n2 arrays of 100 elements, with an intersection of size 10...\nfast_array_intersect x 104,023 ops/sec ±0.30% (92 runs sampled)\nintersect x 28,178 ops/sec ±0.38% (96 runs sampled)\nintersection-of x 30,345 ops/sec ±0.21% (94 runs sampled)\narray-intersection-x x 3,667 ops/sec ±0.32% (97 runs sampled)\nFastest is fast_array_intersect\n\n10 arrays of 100 elements, with an intersection of size 99...\nfast_array_intersect x 41,212 ops/sec ±0.39% (92 runs sampled)\nintersect x 24,863 ops/sec ±0.36% (93 runs sampled)\nintersection-of x 40,573 ops/sec ±0.17% (96 runs sampled)\narray-intersection-x x 2,504 ops/sec ±0.14% (98 runs sampled)\nFastest is fast_array_intersect\n\n10 arrays of 100 elements, with an intersection of size 0...\nfast_array_intersect x 156,244 ops/sec ±0.38% (95 runs sampled)\nintersect x 9,125 ops/sec ±0.29% (95 runs sampled)\nintersection-of x 6,426 ops/sec ±0.24% (97 runs sampled)\narray-intersection-x x 3,695 ops/sec ±0.31% (96 runs sampled)\nFastest is fast_array_intersect\n\n1000 arrays of 10 elements, with an intersection of size 3...\nfast_array_intersect x 4,260 ops/sec ±0.29% (96 runs sampled)\nintersect x 438 ops/sec ±0.81% (92 runs sampled)\nintersection-of x 835 ops/sec ±0.17% (94 runs sampled)\narray-intersection-x x 2,672 ops/sec ±0.60% (95 runs sampled)\nFastest is fast_array_intersect\n\n10 arrays of 1000 elements, with an intersection of size 500...\nfast_array_intersect x 2,701 ops/sec ±0.13% (97 runs sampled)\nintersect x 842 ops/sec ±0.63% (94 runs sampled)\nintersection-of x 1,193 ops/sec ±0.17% (96 runs sampled)\narray-intersection-x x 234 ops/sec ±0.33% (91 runs sampled)\nFastest is fast_array_intersect\n```\n\nFor more details about the benchmark, see [`benchmark.js`](./benchmark.js).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasoa%2Ffast_array_intersect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovasoa%2Ffast_array_intersect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasoa%2Ffast_array_intersect/lists"}