{"id":16125743,"url":"https://github.com/dy/sort-ids","last_synced_at":"2025-08-12T16:40:10.822Z","repository":{"id":55610015,"uuid":"158053881","full_name":"dy/sort-ids","owner":"dy","description":"Calculate ids corresponding to sorting an input array","archived":false,"fork":false,"pushed_at":"2023-08-05T14:35:33.000Z","size":42,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-19T04:35:18.471Z","etag":null,"topics":[],"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/dy.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":"2018-11-18T05:43:43.000Z","updated_at":"2024-03-08T12:06:44.000Z","dependencies_parsed_at":"2024-10-20T08:00:46.887Z","dependency_job_id":"2524a41b-5782-4f77-96be-41b31409badb","html_url":"https://github.com/dy/sort-ids","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"4022724c10d445f5afec80ee3e4ef87ec65b8eb0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dy/sort-ids","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fsort-ids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fsort-ids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fsort-ids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fsort-ids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dy","download_url":"https://codeload.github.com/dy/sort-ids/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fsort-ids/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270099267,"owners_count":24527027,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-09T21:31:23.894Z","updated_at":"2025-08-12T16:40:09.952Z","avatar_url":"https://github.com/dy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sort-ids [![test](https://github.com/dy/sort-ids/actions/workflows/test.yml/badge.svg)](https://github.com/dy/sort-ids/actions/workflows/test.yml)\n\nSort input array, return sorted ids of the array items, keeping the initial array unchanged.\n\nUseful to perform linked sorting of multiple arrays, where linked array[s] should be sorted the same way as the primary one.\n\n[![npm install sort-ids](https://nodei.co/npm/sort-ids.png?mini=true)](https://npmjs.org/package/sort-ids/)\n\n```js\nimport sortIds from 'sort-ids'\nimport reorder from 'array-rearrange'\n\nconst rates = [.12, .47, .52, .97, ...sourceNumbers]\nconst names = ['John', 'Alexa', 'Jimmy', 'Kate', ...linkedItems]\n\nconst ids = sortIds(rates)\n\nconst sortedRates = reorder(rates, ids)\nconst sortedNames = reorder(names, ids)\n```\n\n## `ids = sortIds(array, ids?, precise=true)`\n\nCalculate ids corresponding to sorted input array. The input array isn't changed. Optionally pass input `ids` - some initial order of ids. `precise` flag makes sure no missorts took place and resolves them, if any. Disabling that can save `~30ms` for `1e6` items input arrays.\n\nSee also [array-rearrange](https://ghub.io/array-rearrange) for reordering input array based on a list of ids.\n\n## Motivation\n\nThis package is \u003e= 6 times faster compared to sorting function. That is achieved by packing input `value - id` pairs into a single `float64` value and performing native sort on that _Float64Array_, then unpacking the `ids` back.\n\n\n## Acknowledgement\n\nThe idea was proposed by [Robert Monfera](https://github.com/monfera) for [snap-points-2d](https://ghub.io/snap-points-2d) and eventually implemented. But there may be other applications, like [sorting colors](https://twitter.com/winkerVSbecks/status/1063919602038685697) etc.\n\n## License\n\n(c) 2018 Dmitry Iv. MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fsort-ids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdy%2Fsort-ids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fsort-ids/lists"}