• Welcome to Baben's blog that year. I'm glad to meet you at the right age!
  • Due to the theme, the QQ login partner displays the default avatar in the comments. Please go to the personal center to upload the avatar again.

ES6 array extension: realize union, intersection and subtraction

Code Notes barben 4 years ago (2020-04-02) 2912 views 0 comments

Next, write the last article《 Understand the Set structure in ES6 》At the end of the summary, I saw a【 ES6 Array Extension 】To realize the method of "finding union, intersection and difference sets of two sets".

It is very simple. The implementation method is as follows:

 let a = new Set([1, 2, 3]); let b = new Set([4, 3, 2]); //Union let union = new Set([...a, ...b]); console.log(union); //  Set(4) {1, 2, 3, 4} //Intersection let intersect = new Set([...a].filter(x => b.has(x))); console.log(intersect); //  Set(2) {2, 3} //Difference set let difference = new Set([...a].filter(x => !b.has(x))); console.log(difference); //  Set(1) {1}

 ES6 array extension: realize union, intersection and subtraction - code diagram


Eight blogs that year, we have been
If the author does not indicate that it is an original article, please indicate the link and source of this article for reprinting
ES6 array extension: realize union, intersection and subtraction- https://www.barben.cn/code/752.html
Like( three )
Post my comments
Cancel comment
expression Mapping Bold Strike through Center Italic

You need to bring your nickname and email with you in the review of Eight Books that year!

  • Nickname (required)
  • Email (required)
  • website