Comparing version 0.1.0 to 0.1.1
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 @@ |
{ | ||
"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])); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
9442
311