From 46e3d5f4bcc54506fcb1d0f0c3a3c59fb00c20fc Mon Sep 17 00:00:00 2001 From: koronya Date: Tue, 10 Feb 2026 04:26:41 +0900 Subject: [PATCH] [JS][7kyu] Playing with Sets : Intersection --- .../playing-with-sets-intersection/koronya.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 codewars/7kyu/playing-with-sets-intersection/koronya.js diff --git a/codewars/7kyu/playing-with-sets-intersection/koronya.js b/codewars/7kyu/playing-with-sets-intersection/koronya.js new file mode 100644 index 000000000..9e485c696 --- /dev/null +++ b/codewars/7kyu/playing-with-sets-intersection/koronya.js @@ -0,0 +1,19 @@ +// [JS][7kyu] Playing with Sets : Intersection +// playing-with-sets-intersection +// https://www.codewars.com/kata/5884d46015a70f6cd7000035/train/javascript + +const inter = (s1, s2) => { + const result = new Set() + s1.forEach((item) => { + if (s2.has(item)) { + result.add(item) + } + }) + return result +} + +// es2024 +const inter2 = (s1, s2) => s1.intersection(s2) + +inter(new Set([1, 2]), new Set([2, 3])) +inter2(new Set([1, 2]), new Set([2, 3]))