# @writetome51/array-get-by-test

> Similar to Array.prototype.filter(), except it lets you customize what value to get from the element that passes test

Latest version **4.0.2** (published 2021-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writetome51/array-get-by-test
pnpm add @writetome51/array-get-by-test
yarn add @writetome51/array-get-by-test
bun add @writetome51/array-get-by-test
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2021-04-29 |
| First published | 2019-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | array, manipulation, filter, find, test, return, results |

## Links

- npm: https://www.npmjs.com/package/@writetome51/array-get-by-test
- Repository: https://github.com/writetome51/array-get-by-test
- Homepage: https://github.com/writetome51/array-get-by-test#readme
- Issues: https://github.com/writetome51/array-get-by-test/issues
- npm.io page: https://npm.io/package/@writetome51/array-get-by-test

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 4.0.2 (latest) — 2021-04-29
- 4.0.1 — 2021-04-29
- 4.0.0 — 2021-04-29
- 3.0.0 — 2020-09-06
- 2.0.0 — 2020-08-04
- 1.0.1 — 2019-04-14
- 1.0.0 — 2019-02-25

## README

# getByTest(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test: (value, index?, array?) => boolean,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getValue?: (value, index?, array?) => any<br>): any[]

Similar to Array.prototype.filter(), except it includes optional callback `getValue()`,  
which lets you customize what value to get from the element that passes `test`.  
By default `getValue()` simply returns the element.


## Examples
```js
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
getByTest((value) => value >= 9, arr);
// --> [9, 10]


// Return the value and index of each element that passes:

arr = [50, -10, 100, -20, 1000, -100];
getByTest(
    (value) => value < 0, 
    arr,
    (value, index) => { return {value, index}; }
);
/*************** 
Returns:
[
   {value: -10, index: 1}, 
   {value: -20, index: 3}, 
   {value: -100, index: 5}
]
***************/


// Get only the indexes:

arr = [50, -10, 100, -20, 1000, -100];
getByTest(
    (value) => value < 0, 
    arr, 
    (value, index) => index
);
// --> [1, 3, 5]


// Get the square root of each element that passes:

arr = [-2,-4, 9, 16];
getByTest(
    (value) => value > 0,
    arr,
    (value) => Math.sqrt(value)
);
// --> [3, 4]
```

## Installation
`npm i  @writetome51/array-get-by-test`

## Loading
```ts
import {getByTest} from '@writetome51/array-get-by-test';
```

---
_Source: https://npm.io/package/@writetome51/array-get-by-test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
