1.3.2 • Published 5 years ago

sparse-array v1.3.2

Weekly downloads
7,046
License
ISC
Repository
github
Last release
5 years ago

sparse-array

Build Status

Sparse array implementation in JS with no dependencies

Install

$ npm install sparse-array --save

Use

Create:

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

Set, get and unset:

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

arr.get(index) // 'value'

arr.unset(index)

arr.get(index) // undefined

Iterate:

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:

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

Internal representation:

Bit field:

const bitField = arr.bitField()

Compact array:

const compacted = arr.compactArray()

License

ISC

1.3.2

5 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago