JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 115474
  • Score
    100M100P100Q207599F
  • License ISC

Sparse array implementation in JS with no dependencies

Package Exports

  • sparse-array

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sparse-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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