Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
different operations of set
var new_js = new Set(["Maps", "functions" , "filters" , "generators" , "loops"])
var old_js = new Set(["functions" , "var" , "loops" , "this"])
union(new_js, old_js)
intersection(new_js, old_js)
difference(new_js, old_js)
function union(new_js, old_js) {
var js = new Set(old_js)
for(var item of new_js) {
js.add(item)
}
console.log(js)
}
function intersection(new_js, old_js) {
var js = new Set()
for(var item of new_js) {
if(old_js.has(item)) {
js.add(item)
}
}
console.log(js)
}
function difference(new_js, old_js) {
var js = new Set(new_js)
for(var item of old_js) {
js.delete(item)
}
console.log(js)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment