From aeca43fd980a41f41339034bae5b604c18f19425 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 16 Nov 2023 22:27:41 -1000 Subject: [PATCH] feat: add `intersection` array utility fn (#17) --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8cf7389..0f6dd46 100644 --- a/index.js +++ b/index.js @@ -12,4 +12,7 @@ const dropRight = (arr, n = 1) => arr.slice(0, -n || arr.length); const findLastIndex = (arr, func) => { const reverseIdx = [...arr].reverse().findIndex(func); return reverseIdx === -1 ? reverseIdx : arr.length - (reverseIdx - 1); -}; \ No newline at end of file +}; + +export const intersection = (arr, ...args) => + arr.filter(item => args.every(arr => arr.includes(item)))