{"id":15062504,"url":"https://github.com/sakura90/sorted-array-operations","last_synced_at":"2025-04-10T13:13:14.517Z","repository":{"id":57163526,"uuid":"396411525","full_name":"sakura90/sorted-array-operations","owner":"sakura90","description":"A JavaScript library of sorted array operations","archived":false,"fork":false,"pushed_at":"2021-08-19T23:46:24.000Z","size":69,"stargazers_count":37,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-26T07:45:22.558Z","etag":null,"topics":["binary-search","bisection-method","cdn","commonjs-module","difference","es-module","intersection","javascript","lower-bound","merge","npm","sorted-array","symmetric-difference","typescript","union","upper-bound","yarn"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sakura90.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":"2021-08-15T16:16:59.000Z","updated_at":"2024-04-17T12:14:25.000Z","dependencies_parsed_at":"2022-08-31T22:23:05.387Z","dependency_job_id":null,"html_url":"https://github.com/sakura90/sorted-array-operations","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakura90%2Fsorted-array-operations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakura90%2Fsorted-array-operations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakura90%2Fsorted-array-operations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakura90%2Fsorted-array-operations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sakura90","download_url":"https://codeload.github.com/sakura90/sorted-array-operations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248225653,"owners_count":21068078,"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":["binary-search","bisection-method","cdn","commonjs-module","difference","es-module","intersection","javascript","lower-bound","merge","npm","sorted-array","symmetric-difference","typescript","union","upper-bound","yarn"],"created_at":"2024-09-24T23:41:47.097Z","updated_at":"2025-04-10T13:13:14.326Z","avatar_url":"https://github.com/sakura90.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\u003ca href=\"https://github.com/sakura90/sorted-array-operations\"\u003e\u003cimg src=\"https://sakura90.github.io/moduleLogo.png\" height=\"180\"/\u003e\u003c/a\u003e\u003c/p\u003e\n\u003ch1 align=\"center\"\u003eSorted Array Operations\u003c/h1\u003e\n\u003cp align=\"center\"\u003eSorted array operation module that has a broad operation coverage.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/Unit%20test-passing-brightgreen\" height=\"20\"/\u003e\u003c/a\u003e\n\t\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/Size-2.9kB-green\" height=\"20\"/\u003e\u003c/a\u003e\n\t\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/Maintained%3F-yes-green.svg\" height=\"20\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://twitter.com/intent/tweet?text=Sorted%20array%20operation%20JavaScript%20module\u0026url=https://github.com/sakura90/sorted-array-operations\u0026hashtags=javascript,opensource,js,webdev,developers\"\u003e\u003cimg src=\"http://randojs.com/images/tweetShield.svg\" alt=\"Tweet\" height=\"20\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\u003cbr/\u003e\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://sakura90.github.io/sorted-array-operations-demo-use.gif\" width=\"50%\"/\u003e\u003c/p\u003e\u003cbr/\u003e\n\n## Overview\nExisting libraries cover non-standard operations or cover the operations partially on sorted arrays.\nThis library is created to provide a wide range of operations on sorted arrays found in the standard libraries \nof major programming languages so that developers can get almost all (if not all) standard operations on sorted arrays in a library.\n\nThis library features:\n\n* Language: Supports both JavaScript and TypeScript\n* Module: Includes both CommonJS module and ES module\n\n## Installation\nYarn \u0026 npm\n\n```\n$ yarn add sorted-array-operations\n$ npm install sorted-array-operations\n```\n\nCDN\n\n```\n\u003cscript src=\"https://unpkg.com/sorted-array-operations@1.0.0/dist/utils.esm.js\"\u003e\u003c/script\u003e\n```\n\n## Usage of all library functions\n```js\nconst ops = require('sorted-array-operations');\n\nconsole.log(ops.union([2, 3, 5, 6], [2, 6, 8])); // [ 2, 3, 5, 6, 8 ]\nconsole.log(ops.intersection([2, 3, 5, 6], [2, 6, 8])); // [ 2 ]\nconsole.log(ops.difference([2, 3, 5, 6], [2, 6, 8])); // [ 3, 5 ]\nconsole.log(ops.symmetric_difference([2, 3, 5, 6], [2, 6, 8])); // [ 3, 5, 8 ]\nconsole.log(ops.merge([2, 3, 5, 6], [2, 6, 8])); // [ 2, 2, 3, 5, 6, 6, 8 ]\n\nconst arr1 = [2, 5, 3];\nconsole.log(ops.inplace_merge(arr1, 2)); // arr1 becomes [ 2, 3, 5 ]\n\nconsole.log(ops.includes([2, 3, 5, 6], [2, 6, 8])); // false\n\nconst arr2 = [2, 3, 5, 6];\nconsole.log(ops.insert(arr2, 2)); // arr2 becomes [ 2, 2, 3, 5, 6 ]\n\nconst arr3 = [2, 3, 5, 6];\nconsole.log(ops.remove(arr3, 2)); // Return true. arr3 becomes [ 3, 5, 6 ]\nconsole.log(ops.binary_search([2, 3, 5, 6], 2)); // Return 0\nconsole.log(ops.binary_search_ge([2, 3, 5, 6], 2)); // Return 0\nconsole.log(ops.binary_search_gt([2, 3, 5, 6], 2)); // Return 1\nconsole.log(ops.equal_range([2, 3, 5, 6], 2)); // Return [ 0, 1 ]\n\nfunction weight_cmp(p1, p2) {\n  return p1.weight \u003e p2.weight ? 1 : p1.weight \u003c p2.weight ? -1 : 0;\n}\n\nconsole.log(ops.union([{weight: 2}, {weight: 3}], [{weight: 3}], weight_cmp)); // [ {weight: 2}, {weight: 3} ]\nconsole.log(ops.intersection([{weight: 2}, {weight: 3}], [{weight: 3}], weight_cmp)); // [ {weight: 3} ]\nconsole.log(ops.difference([{weight: 2}, {weight: 3}], [{weight: 3}], weight_cmp)); // [ {weight: 2} ]\nconsole.log(ops.symmetric_difference([{weight: 2}, {weight: 3}], [{weight: 3},{weight: 4}], weight_cmp)); // [ {weight: 2}, {weight: 4} ]\nconsole.log(ops.merge([{weight: 2}, {weight: 3}], [{weight: 3}], weight_cmp)); // [ {weight: 2}, {weight: 3}, {weight: 3} ]\n\nconst arr4 = [{weight: 3}, {weight: 1}];\nconsole.log(ops.inplace_merge(arr4, 1, weight_cmp)); // arr4 becomes [ {weight: 1}, {weight: 3} ]\n\nconsole.log(ops.includes([{weight: 2}, {weight: 3}], [{weight: 3}], weight_cmp)); // true\n\nconst arr5 = [{weight: 3}];\nconsole.log(ops.insert(arr5, {weight: 2}, weight_cmp)); // arr5 becomes [ {weight: 2}, {weight: 3} ]\n\nconst arr6 = [{weight: 3}];\nconsole.log(ops.remove(arr6, {weight: 3}, weight_cmp)); // Return true. arr6 becomes [ ]\nconsole.log(ops.binary_search([{weight: 2}, {weight: 3}], {weight: 2}, weight_cmp)); // Return 0\nconsole.log(ops.binary_search_ge([{weight: 2}, {weight: 3}], {weight: 2}, weight_cmp)); // Return 0\nconsole.log(ops.binary_search_gt([{weight: 2}, {weight: 3}], {weight: 2}, weight_cmp)); // Return 1\nconsole.log(ops.equal_range([{weight: 2}, {weight: 3}], {weight: 2}, weight_cmp)); // Return [ 0, 1 ]\n```\n\n## Related libraries\nThe library most similar to this library is [sorted-array-functions](https://www.npmjs.com/package/sorted-array-functions).\nThis library has the set operations on sorted arrays and follows the way of implementing `lower_bound` and `upper_bound`\nin the standard libraries in C++ and Python.  These 2 differences are the major differences between this library and \n[sorted-array-functions](https://www.npmjs.com/package/sorted-array-functions).\nOther related libraries can be found in Google search.\n\n## Contributing\nThe sorted array operation library welcomes patches/pulls for features and bug fixes.  Please open an issue and send a PR request!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakura90%2Fsorted-array-operations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsakura90%2Fsorted-array-operations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakura90%2Fsorted-array-operations/lists"}