Created
April 27, 2020 16:22
-
-
Save essamamdani/3e137641e56704a5edb0d18aedac1d65 to your computer and use it in GitHub Desktop.
different operations of set
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
| 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