{"id":17767307,"url":"https://github.com/jamiebuilds/outward-search","last_synced_at":"2025-03-15T13:31:16.021Z","repository":{"id":57316968,"uuid":"106073534","full_name":"jamiebuilds/outward-search","owner":"jamiebuilds","description":"Search an array of items outwards from a starting index","archived":false,"fork":false,"pushed_at":"2017-10-07T23:21:41.000Z","size":38,"stargazers_count":9,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T00:08:03.529Z","etag":null,"topics":["array","binary-search","find","search"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"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/jamiebuilds.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":"2017-10-07T05:22:23.000Z","updated_at":"2020-02-24T19:07:02.000Z","dependencies_parsed_at":"2022-08-25T21:11:08.726Z","dependency_job_id":null,"html_url":"https://github.com/jamiebuilds/outward-search","commit_stats":null,"previous_names":["thejameskyle/outward-search"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Foutward-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Foutward-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Foutward-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Foutward-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamiebuilds","download_url":"https://codeload.github.com/jamiebuilds/outward-search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243735843,"owners_count":20339536,"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":["array","binary-search","find","search"],"created_at":"2024-10-26T20:46:00.821Z","updated_at":"2025-03-15T13:31:15.721Z","avatar_url":"https://github.com/jamiebuilds.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# outward-search\n\n\u003e Search an array of items outwards from a starting index\n\n## Install\n\n```sh\nyarn add outward-search\n```\n\n## Usage\n\n```js\nimport outwardSearch from 'outward-search';\n\nlet arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];\n\nlet match = searchOutwards(arr, 3, (item, index) =\u003e {\n  console.log('called: ' + item);\n  return item === 'e';\n});\n\n// called: d\n// called: e\n// called: c\n// called: f\nconsole.log(match); // 'f'\n```\n\nIf you need to find an item in an array that you know should be near another\nitem, you can use outward-search to do so efficiently.\n\n```js\nexport default function outwardSearch\u003cT\u003e(\n  items: Array\u003cT\u003e,\n  start: number,\n  callback: (item: T, index: number) =\u003e boolean,\n): T | null;\n```\n\nThe `callback` is called on the `start` index then it works its way outwards to\neither end of the array.\n\nSo with the starting index of `2` and an array with 8 items:\n\n```js\n2 // start\n3 // up\n1 // down\n4 // up\n0 // down (hit min)\n5 // up\n6 // up\n7 // up (hit max)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiebuilds%2Foutward-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamiebuilds%2Foutward-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiebuilds%2Foutward-search/lists"}