Created
March 5, 2022 22:06
-
-
Save black1277/118f74040fe233546562852cfaef07f8 to your computer and use it in GitHub Desktop.
Операции над множествами
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Объединение без дублирования: | |
const a = new Set([1,2,3]); | |
const b = new Set([4,3,2]); | |
const union = new Set([...a, ...b]); | |
// {1,2,3,4} | |
Пересечение: | |
const a = new Set([1,2,3]); | |
const b = new Set([4,3,2]); | |
const intersection = new Set( | |
[...a].filter(x => b.has(x)) | |
); | |
// {2,3} | |
Разность: | |
const a = new Set([1,2,3]); | |
const b = new Set([4,3,2]); | |
const difference = new Set( | |
[...a].filter(x => !b.has(x))); | |
// {1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment