Skip to content

Commit

Permalink
feat: add intersection array utility fn (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ze-flo authored Nov 17, 2023
1 parent b8bdf7c commit aeca43f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};

export const intersection = (arr, ...args) =>
arr.filter(item => args.every(arr => arr.includes(item)))

0 comments on commit aeca43f

Please sign in to comment.