I want to add an item to a Set
without mutating the original set. I tried using add()
but this mutates the original:
var s = new Set();
var s1 = s.add('foo');
console.log('s has foo:', s.has('foo'));
console.log('s1 has foo:', s1.has('foo'));
How can I create a new set by adding an item to it, without mutating the original set?