Comparing version 0.0.11 to 0.0.12
@@ -132,20 +132,41 @@ // Load modules | ||
if (array) { | ||
var obj = {}; | ||
for (var i = 0, il = array.length; i < il; ++i) { | ||
if (key) { | ||
if (array[i][key]) { | ||
obj[array[i][key]] = true; | ||
} | ||
if (!array) { | ||
return null; | ||
} | ||
var obj = {}; | ||
for (var i = 0, il = array.length; i < il; ++i) { | ||
if (key) { | ||
if (array[i][key]) { | ||
obj[array[i][key]] = true; | ||
} | ||
else { | ||
obj[array[i]] = true; | ||
} | ||
} | ||
else { | ||
obj[array[i]] = true; | ||
} | ||
} | ||
return obj; | ||
return obj; | ||
}; | ||
// Find the common unique items in two arrays | ||
exports.intersect = function (array1, array2) { | ||
if (!array1 || !array2) { | ||
return []; | ||
} | ||
else { | ||
return null; | ||
var common = []; | ||
var hash = exports.mapToObject(array1); | ||
var found = {}; | ||
for (var i = 0, il = array2.length; i < il; ++i) { | ||
if (hash[array2[i]] && !found[array2[i]]) { | ||
common.push(array2[i]); | ||
found[array2[i]] = true; | ||
} | ||
} | ||
return common; | ||
}; | ||
@@ -152,0 +173,0 @@ |
{ | ||
"name": "hoek", | ||
"description": "General purpose node utilities", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors":[ |
@@ -80,2 +80,14 @@ var assert = require('assert'); | ||
describe('#intersect', function () { | ||
it('should return the common objects of two arrays', function (done) { | ||
var array1 = [1, 2, 3, 4, 4, 5, 5]; | ||
var array2 = [5, 4, 5, 6, 7]; | ||
var common = Hoek.intersect(array1, array2); | ||
common.length.should.equal(2); | ||
done(); | ||
}); | ||
}); | ||
describe('#removeKeys', function () { | ||
@@ -82,0 +94,0 @@ |
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
16795
373