Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const hasUniqueFrequencies = <T>(array: T[]): boolean => {
- const itemCountMap = new Map<T, number>();
- for (const item of array) {
- const itemCount = itemCountMap.get(item);
- if (itemCount)
- itemCountMap.set(item, itemCount + 1);
- else
- itemCountMap.set(item, 1);
- }
- const countSet = new Set<number>(itemCountMap.values());
- return itemCountMap.size === countSet.size;
- }
- const array = [2, 2, 3, 3, 3];
- console.log(hasUniqueFrequencies(array));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement