I'm not sure if I'm very tired right now, but for some reason I can't get my head around this:
const A = new Set([1, 2, 3, 4, 5]);
const B = new Set([4, 5, 6, 7, 8]);
const C = new Set([9, 10]);
function exercise09(arg1, arg2) {
var union = arg1;
for (let elem of arg2) {
union.add(elem);
}
console.log(union.size);
}
exercise09(A, A); // Should yield 5
exercise09(A, B); // Should yield 8
exercise09(A, C); // Should yield 7
If i run them independently I get the correct results, but when run consecutively they affect each other.
The 3rd call gives 10 instead of 7 when runned after the 2 first calls.
The value of "A" changes to contain 8 elements after the second call?
I don't understand why the function calls are affecting one and other?