This function compares two sets for equality, regardless of the order of elements.
JavaScript:
let areSetsEqual = (set1, set2) => set1.size === set2.size && [...set1].every(val => set2.has(val));
// Example
console.log(areSetsEqual(new Set([1, 2, 3]), new Set([3, 2, 1]))); // true
console.log(areSetsEqual(new Set(['a', 'b']), new Set(['a', 'c']))); // false
TypeScript:
let areSetsEqual = (set1: Set, set2: Set): boolean => set1.size === set2.size && [...set1].every(val => set2.has(val));
// Example
console.log(areSetsEqual(new Set([1, 2, 3]), new Set([3, 2, 1]))); // true
console.log(areSetsEqual(new Set(['a', 'b']), new Set(['a', 'c']))); // false