Comparing version 0.1.1 to 0.1.3
@@ -37,4 +37,5 @@ Array.prototype.equals = Array.prototype.compare = function equals(array) { | ||
for (var j = i + 1; j < a.length; ++j) { | ||
if (a[i] === a[j]) | ||
if (JSON.stringify(a[i]) === JSON.stringify(a[j])) { | ||
a.splice(j--, 1); | ||
} | ||
} | ||
@@ -41,0 +42,0 @@ } |
{ | ||
"name": "array-util", | ||
"version": "0.1.1", | ||
"version": "0.1.3", | ||
"description": "Array utils for misc. but useful things, so far just compares arrays", | ||
@@ -5,0 +5,0 @@ "main": "./lib/util", |
@@ -6,3 +6,3 @@ ArrayUtil | ||
###Array.prototype.merge | ||
>Uniquely merge two arrays. This only works with elements that are primitives | ||
>Uniquely merge two arrays (even with object elements). | ||
@@ -9,0 +9,0 @@ ###Array.prototype.equals |
require('../lib/util.js'); | ||
var assert = require('chai').assert; | ||
describe('Array',function(){ | ||
describe('#merge',function(){ | ||
it('Should contain values of both arrays after calling merge',function(){ | ||
var array = [1,2,3]; | ||
var array_2 = [3,4,5,6]; | ||
assert(array.merge(array_2).equals([1, 2, 3, 4, 5, 6])); | ||
}); | ||
}); | ||
describe('Array', function() { | ||
describe('#merge', function() { | ||
it('Should contain values of both arrays after calling merge', function() { | ||
var array = [1, 2, 3]; | ||
var array_2 = [3, 4, 5, 6]; | ||
assert(array.merge(array_2).equals([1, 2, 3, 4, 5, 6])); | ||
}); | ||
it('Should properly and uniquely merge intersecting arrays with objects', function() { | ||
var array = [{ | ||
name: 'John' | ||
}, { | ||
name: 'Jane' | ||
}], | ||
array2 = [{ | ||
name: 'John' | ||
}, { | ||
name: 'Fred' | ||
}], | ||
expected = [{ | ||
name: 'John' | ||
}, { | ||
name: 'Jane' | ||
}, { | ||
name: 'Fred' | ||
}]; | ||
assert(array.merge(array2).equals(expected)); | ||
}); | ||
}); | ||
}); |
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
9951
332