@humanspeak/svelte-headless-table
Version:
A powerful, headless table library for Svelte that provides complete control over table UI while handling complex data operations like sorting, filtering, pagination, grouping, and row expansion. Build custom, accessible data tables with zero styling opin
34 lines (33 loc) • 1.08 kB
JavaScript
import { getCounter } from './counter.js';
/**
* Returns an array containing only the distinct elements from the input array.
* Preserves the order of first occurrence.
*
* @template T - The type of elements in the array.
* @param items - The input array potentially containing duplicates.
* @returns A new array with duplicate elements removed.
* @example
* ```typescript
* getDistinct([1, 2, 2, 3, 1]) // Returns [1, 2, 3]
* ```
*/
export const getDistinct = (items) => {
return Array.from(getCounter(items).keys());
};
/**
* Returns an array containing only the elements that appear more than once
* in the input array.
*
* @template T - The type of elements in the array.
* @param items - The input array to check for duplicates.
* @returns A new array containing only duplicate elements.
* @example
* ```typescript
* getDuplicates([1, 2, 2, 3, 1]) // Returns [1, 2]
* ```
*/
export const getDuplicates = (items) => {
return Array.from(getCounter(items).entries())
.filter(([, count]) => count !== 1)
.map(([key]) => key);
};