# @johngw/array

> JS/TS array utils.

Latest version **3.3.2** (published 2023-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @johngw/array
pnpm add @johngw/array
yarn add @johngw/array
bun add @johngw/array
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.3.2 |
| Published | 2023-05-19 |
| First published | 2020-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | John Wright <johngeorge.wright@gmail.com> |
| Maintainers | johngeorgewright |

## Links

- npm: https://www.npmjs.com/package/@johngw/array
- Homepage: https://github.com/johngeorgewright/js-util#readme
- Issues: https://github.com/johngeorgewright/js-util/issues
- npm.io page: https://npm.io/package/@johngw/array

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) 2.5.2

## Recent versions

- 3.3.2 (latest) — 2023-05-19
- 3.3.1 — 2023-05-10
- 3.3.0 — 2021-10-27
- 3.2.0 — 2021-10-20
- 3.1.5 — 2021-06-09
- 3.1.4 — 2021-05-28
- 3.1.0 — 2021-05-25
- 3.0.0 — 2021-04-05
- 2.1.1 — 2021-04-05
- 2.1.0 — 2021-03-31
- 2.0.0 — 2021-03-26
- 1.2.0 — 2021-02-14
- 1.1.1 — 2020-12-18
- 1.1.0 — 2020-12-17
- 1.0.0 — 2020-12-15
- … 1 more at https://npm.io/package/@johngw/array/versions

## README

# @johngw/array

## filterMap

> Filters and maps an array in 1 loop

```typescript
filterMap(
  [1, 2, 3, 4, 5, 6, 7, 8, 9],
  (x) as is number => x > 5,
  (x) => `${x} bottles`
)
/*
  [
    '6 bottles',
    '7 bottles',
    '8 bottles',
    '9 bottles',
  ]
*/
```

## filterReduce

> Filters and reduces an array in 1 loop

```typescript
filterReduce(
  [1, 2, 3, 4, 5, 6, 7, 8, 9],
  0,
  (_, x) => x < 5,
  (sum, x) => sum + x
)
// 10
```

## Builder

> Performant array builder

This is used internally to build arrays. It performs 3x faster than just appending items to array with undefined length.

```typescript
const builder = new Builder<number>(10_000)

for (let i = 0; i < 10_000; i++) {
  builder.add(i)
}

builder.finish()
// [0, 1, 2, 3, ..., 9999]
```

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