Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Set(), union, intersection, difference
//JavaScript-C24.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
0
rotateMatrix
100034322376708
js
Javascript reverse string, one index
LearningJavaScript
Iterator()-function
Bhbhbh
fb_series
Javascript is weird
game green