April 2018
Beginner to intermediate
426 pages
10h 19m
English
There is a simpler way of simulating the union, intersection, and difference operations by using the spread operator, also introduced in ES2015 that we learned in Chapter 2, ECMAScript and TypeScript Overview.
The process consists of three steps:
Let's see how we can perform the set union operation using the spread operator:
console.log(new Set([...setA, ...setB]));
The ES2015 Set class also accepts passing an array directly in its constructor to initialize the set with values, so we apply the spread operator in setA (...setA), which will transform its values in an array (will spread its values) and we do the ...