This function creates a set from an array. The set contains all unique elements of the array.
JavaScript:
let setFromArray = arr => new Set(arr);
// Example
console.log(setFromArray([1, 2, 2, 3, 4, 4, 5])); // Set [1, 2, 3, 4, 5]
console.log(setFromArray(['a', 'b', 'b', 'c'])); // Set ['a', 'b', 'c']
TypeScript:
let setFromArray = (arr: T[]): Set => new Set(arr);
// Example
console.log(setFromArray([1, 2, 2, 3, 4, 4, 5])); // Set [1, 2, 3, 4, 5]
console.log(setFromArray(['a', 'b', 'b', 'c'])); // Set ['a', 'b', 'c']