Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@hapi/hoek/lib/intersect.js
1126 views
1
'use strict';
2
3
const internals = {};
4
5
6
module.exports = function (array1, array2, options = {}) {
7
8
if (!array1 ||
9
!array2) {
10
11
return (options.first ? null : []);
12
}
13
14
const common = [];
15
const hash = (Array.isArray(array1) ? new Set(array1) : array1);
16
const found = new Set();
17
for (const value of array2) {
18
if (internals.has(hash, value) &&
19
!found.has(value)) {
20
21
if (options.first) {
22
return value;
23
}
24
25
common.push(value);
26
found.add(value);
27
}
28
}
29
30
return (options.first ? null : common);
31
};
32
33
34
internals.has = function (ref, key) {
35
36
if (typeof ref.has === 'function') {
37
return ref.has(key);
38
}
39
40
return ref[key] !== undefined;
41
};
42
43