{"id":22945135,"url":"https://github.com/seregpie/nearestneighborchain","last_synced_at":"2025-07-19T08:04:14.083Z","repository":{"id":57140007,"uuid":"75399436","full_name":"SeregPie/NearestNeighborChain","owner":"SeregPie","description":"Builds a hierarchy of the clusters.","archived":false,"fork":false,"pushed_at":"2020-02-28T14:39:51.000Z","size":6,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-05T12:07:28.543Z","etag":null,"topics":["algorithm","array","cluster","clustering","collection","distance","hierarchical","hierarchy","javascript","method","object","technique"],"latest_commit_sha":null,"homepage":"","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/SeregPie.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}},"created_at":"2016-12-02T13:47:56.000Z","updated_at":"2024-12-19T18:00:16.000Z","dependencies_parsed_at":"2022-09-04T10:20:27.957Z","dependency_job_id":null,"html_url":"https://github.com/SeregPie/NearestNeighborChain","commit_stats":null,"previous_names":["seregpie/almete.nearestneighborchain"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SeregPie/NearestNeighborChain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeregPie%2FNearestNeighborChain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeregPie%2FNearestNeighborChain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeregPie%2FNearestNeighborChain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeregPie%2FNearestNeighborChain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SeregPie","download_url":"https://codeload.github.com/SeregPie/NearestNeighborChain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeregPie%2FNearestNeighborChain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265904251,"owners_count":23846673,"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":["algorithm","array","cluster","clustering","collection","distance","hierarchical","hierarchy","javascript","method","object","technique"],"created_at":"2024-12-14T14:29:50.226Z","updated_at":"2025-07-19T08:04:14.038Z","avatar_url":"https://github.com/SeregPie.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NearestNeighborChain\n\n`NearestNeighborChain(values, distance)`\n\nBuilds a hierarchy of the clusters.\n\n| argument | description |\n| ---: | :--- |\n| `values` | An iterable of the values to build the hierarchy of the clusters from. |\n| `distance` | A function to calculate the distance between two values. The value pairs with the lowest distance build a cluster. |\n\nReturns the clustered values as a nested array.\n\n## dependencies\n\n- [BronKerbosch](https://github.com/SeregPie/BronKerbosch)\n\n## setup\n\n### npm\n\n```shell\nnpm install @seregpie/nearest-neighbor-chain\n```\n\n### ES module\n\n```javascript\nimport NearestNeighborChain from '@seregpie/nearest-neighbor-chain';\n```\n\n### Node\n\n```javascript\nlet NearestNeighborChain = require('@seregpie/nearest-neighbor-chain');\n```\n\n### browser\n\n```html\n\u003cscript src=\"https://unpkg.com/@seregpie/bron-kerbosch\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/@seregpie/nearest-neighbor-chain\"\u003e\u003c/script\u003e\n```\n\nThe module is globally available as `NearestNeighborChain`.\n\n## usage\n\n```javascript\nlet array = [4, 90, 12, 61, 29];\nlet clusters = NearestNeighborChain(array, (a, b) =\u003e Math.abs(a - b));\n// =\u003e [[29, [4, 12]], [90, 61]]\n```\n\n---\n\nOverlapping clusters are merged together.\n\n```javascript\nlet intersection = function(a, b) {\n  a = new Set(a);\n  b = new Set(b);\n  return [...a].filter(v =\u003e b.has(v));\n};\nlet array = ['ac', 'ab', 'baab', 'aba', 'bc'];\nlet clusters = NearestNeighborChain(array, (a, b) =\u003e -intersection(a, b).length);\n// =\u003e ['ac', 'bc', ['ab', 'baab', 'aba']]\n```\n\n## see also\n\n- [KMeans](https://github.com/SeregPie/KMeans)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseregpie%2Fnearestneighborchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseregpie%2Fnearestneighborchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseregpie%2Fnearestneighborchain/lists"}