# sparse-array

> Sparse array implementation in JS with no dependencies

Latest version **1.3.2** (published 2018-12-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install sparse-array
pnpm add sparse-array
yarn add sparse-array
bun add sparse-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 | 1.3.2 |
| Published | 2018-12-04 |
| First published | 2017-01-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | pgte |
| Maintainers | pgte |
| Keywords | sparse, array, sparse, array |

## Links

- npm: https://www.npmjs.com/package/sparse-array
- Repository: https://github.com/pgte/js-sparse-array
- Homepage: https://github.com/pgte/js-sparse-array#readme
- Issues: https://github.com/pgte/js-sparse-array/issues
- npm.io page: https://npm.io/package/sparse-array

## Recent versions

- 1.3.2 (latest) — 2018-12-04
- 1.3.1 — 2017-01-26
- 1.3.0 — 2017-01-25
- 1.2.1 — 2017-01-24
- 1.2.0 — 2017-01-24
- 1.1.2 — 2017-01-24
- 1.1.1 — 2017-01-24
- 1.1.0 — 2017-01-24
- 1.0.0 — 2017-01-24

## README

# sparse-array

[![Build Status](https://travis-ci.org/pgte/js-sparse-array.svg?branch=master)](https://travis-ci.org/pgte/js-sparse-array)

Sparse array implementation in JS with no dependencies

## Install

```bash
$ npm install sparse-array --save
```

## Use

### Create:

```js
const SparseArray = require('sparse-array')
const arr = new SparseArray()
```

### Set, get and unset:

```js
const index = 0
arr.set(index, 'value')

arr.get(index) // 'value'

arr.unset(index)

arr.get(index) // undefined
```

### Iterate:

```js
arr.forEach((elem, index) => {
  console.log('elem: %j at %d', elem, index)
})

const mapped = arr.map((elem, index) => {
  return elem + 1
})

const result = arr.reduce((acc, elem, index) => {
  return acc + Number(elem)
}, 0)
```

### Find:

```js
const firstEven = arr.find((elem) => (elem % 2) === 0)
```

### Internal representation:

#### Bit field:

```js
const bitField = arr.bitField()
```

#### Compact array:

```js
const compacted = arr.compactArray()
```

## License

ISC

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