获取2个数组的交集

JavaScript

const intersection = (a, b) => {
	const s = new Set(b)
	return [...new Set(a)].filter(x => s.has(x))
}

Examples

intersection([1, 2, 3], [4, 3, 2]); // [2, 3]

posted on 2022-09-07 10:09  小馬過河﹎  阅读(19)  评论(0)    收藏  举报

导航