{"id":15854364,"url":"https://github.com/afeiship/filter2tuple","last_synced_at":"2025-10-15T14:40:44.651Z","repository":{"id":193160636,"uuid":"688262404","full_name":"afeiship/filter2tuple","owner":"afeiship","description":"A function to split an array into two tuples based on a filtering condition.","archived":false,"fork":false,"pushed_at":"2023-09-07T02:22:40.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-07T12:31:58.044Z","etag":null,"topics":["array","filter","split","tuple"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/afeiship.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2023-09-07T01:48:38.000Z","updated_at":"2023-09-07T01:58:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"e14045b6-c330-4396-84ce-fa2622426b6f","html_url":"https://github.com/afeiship/filter2tuple","commit_stats":null,"previous_names":["afeiship/filter2tuple"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Ffilter2tuple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Ffilter2tuple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Ffilter2tuple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Ffilter2tuple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afeiship","download_url":"https://codeload.github.com/afeiship/filter2tuple/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246698133,"owners_count":20819497,"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","filter","split","tuple"],"created_at":"2024-10-05T19:41:40.914Z","updated_at":"2025-10-15T14:40:39.605Z","avatar_url":"https://github.com/afeiship.png","language":"TypeScript","readme":"# filter2tuple\n\u003e A function to split an array into two tuples based on a filtering condition.\n\n[![version][version-image]][version-url]\n[![license][license-image]][license-url]\n[![size][size-image]][size-url]\n[![download][download-image]][download-url]\n\n## installation\n```shell\nnpm install @jswork/filter2tuple\n```\n\n## usage\n```js\nimport filter2tuple from '@jswork/filter2tuple';\n\nconst numbers = [1, 2, 3, 4, 5, 6];\nconst [even, odd] = filter2tuple(numbers, (item) =\u003e item % 2 === 0);\n\nconsole.log(even, odd);\n// [2, 4, 6] [1, 3, 5]\n```\n\n## other\n\u003e Use reduce implement:\n\n```js\n// impl1:\nfunction filter2tuple(arr, filterFn) {\n  return arr.reduce((result, item) =\u003e {\n    filterFn(item) ? result[0].push(item) : result[1].push(item);\n    return result;\n  }, [[], []]);\n}\n\n// impl2: \nfunction filter2tuple(arr, filterFn) {\n  return arr.reduce(\n    (result, item) =\u003e {\n      const idx = Number(!filterFn(item));\n      result[idx].push(item);\n      return result;\n    },\n    [[], []]\n  );\n}\n```\n\n## license\nCode released under [the MIT license](https://github.com/afeiship/filter2tuple/blob/master/LICENSE.txt).\n\n[version-image]: https://img.shields.io/npm/v/@jswork/filter2tuple\n[version-url]: https://npmjs.org/package/@jswork/filter2tuple\n\n[license-image]: https://img.shields.io/npm/l/@jswork/filter2tuple\n[license-url]: https://github.com/afeiship/filter2tuple/blob/master/LICENSE.txt\n\n[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/filter2tuple\n[size-url]: https://github.com/afeiship/filter2tuple/blob/master/dist/index.min.js\n\n[download-image]: https://img.shields.io/npm/dm/@jswork/filter2tuple\n[download-url]: https://www.npmjs.com/package/@jswork/filter2tuple\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafeiship%2Ffilter2tuple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafeiship%2Ffilter2tuple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafeiship%2Ffilter2tuple/lists"}