New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sparse-array

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparse-array

Sparse array implementation in JS with no dependencies

  • 1.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
62K
increased by10.62%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 04 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc