Skip to content

Commit 4541adf

Browse files
committed
intersection a built-in method
1 parent 75f9d8b commit 4541adf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Sprint-1/JavaScript/findCommonItems/findCommonItems.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
// ];
1515

1616
export const findCommonItems = (firstArray, secondArray) => {
17-
let firstArr = new Set(firstArray);
18-
let secondArr = new Set(secondArray);
17+
const firstArr = new Set(firstArray);
18+
const secondArr = new Set(secondArray);
1919

20-
return [...firstArr].filter((arr) => secondArr.has(arr));
20+
// return [...firstArr].filter((arr) => secondArr.has(arr));
21+
return [...firstArr.intersection(secondArr)];
2122
};
2223

2324
// * https://www.w3schools.com/js/js_set_methods.asp#mark_set_new

0 commit comments

Comments
 (0)