Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hasharray

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hasharray - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

2

package.json

@@ -6,3 +6,3 @@ {

"description": "A data structure that combines a hash and an array for CRUD operations by object keys or index.",
"version": "0.1.5",
"version": "0.1.6",
"main": "index.js",

@@ -9,0 +9,0 @@ "url": "https://github.com/joshjung/hash-array",

@@ -41,2 +41,5 @@ var JClass = require('jclass');

},
addAll: function (arr) {
this.add.apply(this, arr);
},
addMap: function(key, obj) {

@@ -64,2 +67,33 @@ this._map[key] = obj;

},
getUniqueRandomIntegers: function (count, min, max) {
var res = [], map = {};
count = Math.min(max - min, count);
while (res.length < count)
{
var r = Math.floor(min + (Math.random() * (max + 1)));
if (map[r]) continue;
map[r] = true;
res.push(r);
}
return res;
},
sample: function (count, keys) {
// http://en.wikipedia.org/wiki/Image_(mathematics)
var image = this.all,
ixs = {},
res = [];
if (keys)
image = this.getAll(keys);
var rand = this.getUniqueRandomIntegers(count, 0, image.length - 1);
for (var i = 0; i < rand.length; i++)
res.push(image[rand[i]]);
return res;
},
has: function(key) {

@@ -66,0 +100,0 @@ return this._map.hasOwnProperty(key);

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