UNPKG
tyro-util
Version:
latest (2.5.3)
2.5.3
2.5.2
2.5.1
2.5.0
2.4.0
2.3.0
2.2.1
2.2.0
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.0
1.1.0
1.0.0
前端常用工具库
github.com/tyrocjh/my-util
tyrocjh/my-util
tyro-util
/
lib
/
intersection.js
16 lines
(14 loc)
•
298 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/** *
@description
两数组的交集 *
@param
{
Array
}
a
*
@param
{
Array
}
b
*
@return
{
Array
} * * eg. * intersection([1, 2, 3], [4, 3, 2]); // [2, 3] */
const
intersection
= (
a, b
) => {
const
s =
new
Set
(b)
return
a.
filter
(
x
=>
s.
has
(x)) }
module
.
exports
= intersection