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

array-util

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-util - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

16

lib/util.js
Array.prototype.equals = Array.prototype.compare = function equals(array) {
if (!Array.isArray(array) || this.length !== array.length) {
return false;
}
for (var i = 0; i < this.length; i++) {
// Check if we have nested arrays
if (this[i] instanceof Array && array[i] instanceof Array) {
// recurse into the nested arrays
if (!this[i].equals(array[i])) {
return false;
}
} else if (this[i] !== array[i]) {
return false;
}
}
return true;
return JSON.stringify(this) === JSON.stringify(array);
};

@@ -18,0 +4,0 @@

2

package.json
{
"name": "array-util",
"version": "0.1.0",
"version": "0.1.1",
"description": "Array utils for misc. but useful things, so far just compares arrays",

@@ -5,0 +5,0 @@ "main": "./lib/util",

@@ -12,3 +12,17 @@ require('../lib/util.js');

});
it('Should accurately compare arrays with object elements', function() {
var thingA = {
name: 'thing'
},
thingB = {
name: 'thing'
},
thingC = {
name: false
};
assert([thingA].equals([thingB]));
assert(![thingA].equals([thingC]));
});
});
});
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