Run Code

API

Code Wall

Users

Misc

Feedback

Login

Theme

Privacy

Patreon
Set(), union, intersection, difference
//JavaScriptC24.2.0 (SpiderMonkey) let a = [1,2,3] let b = [4,3,2] let as = new Set(a); let bs = new Set(b); let union = new Set([...a, ...b]); union = [...union] let intersection = new Set(a.filter(x => bs.has(x))) intersection = [...intersection] let differenceInA = new Set(a.filter(x => !bs.has(x))) let differenceInB = new Set(b.filter(x => !as.has(x))) const difference = [...differenceInA, ...differenceInB] print("Array a: ", a) print("Array b: ", b) print("===>") print("union: ", union) print("intersection: ", intersection) print("difference: ", difference)
run

edit

history

help
1
Please
log in
to post a comment.
Viktor Schelochkov
My first app
9
Animal categories
Probability
Узнать значени синуса в радианах
Logical NOT in JavaScript
10 bottles of juice
Reverse strings
Time it has been since Tuesday, January 1st, 2019
Please log in to post a comment.