How to do it...

  1. Open your command-line application, and navigate to your workspace.
  2. Create a new folder named 12-05-set-union.
  3. Create a main.js file that defines a new class named Rocket that takes a constructor argument name and assigns it to an instance property:
// main.js 
class Rocket { 
  constructor(name) { 
    this.name = name; 
  } 
   }  
  1. Create a function called union that takes two set arguments:
// main.js 
function union (set1, set2) {}  
  1. Create a result set. Loop through both set instances, and add each entry to the resultant set:
// main.js 
function union (set1, set2) { 
  const result = new Set(); 
 
  set1.forEach((entry) => result.add(entry)); 
  set2.forEach((entry) => result.add(entry)); 
 
  return result; 
} 
  1. Create a main function. Create a couple ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.