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 - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

tests/test-collections.js

46

index.js

@@ -12,2 +12,4 @@ 'use strict'

this._data = []
this._changed = false
this._length = 0
}

@@ -30,2 +32,3 @@

}
this._changed = true
}

@@ -45,2 +48,45 @@

push (value) {
this.set(this.length, value)
return this.length
}
get length () {
if (this._changed) {
this._length = this._bitArrays.reduce(popCountReduce, 0)
this._changed = false
}
return this._length
}
forEach (iterator) {
let i = 0
while(i < this.length) {
iterator(this.get(i), i, this)
i++
}
}
map (iterator) {
let i = 0
let mapped = new Array(this.length)
while(i < this.length) {
mapped[i] = iterator(this.get(i), i, this)
i++
}
return mapped
}
reduce (reducer, initialValue) {
let i = 0
let acc = initialValue
while(i < this.length) {
acc = reducer(acc, this.get(i), i)
i++
}
return acc
}
_internalPositionFor (index, noCreate) {

@@ -47,0 +93,0 @@ const bytePos = this._bytePosFor(index, noCreate)

2

package.json
{
"name": "sparse-array",
"version": "1.0.0",
"version": "1.1.0",
"description": "Sparse array implementation in JS with no dependencies",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,16 +15,40 @@ # sparse-array

```
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)
```
## License
ISC
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