All files / src/utils/unique-by unique-by.ts

100% Statements 9/9
100% Branches 3/3
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16    95x 10x 10x 28x 28x 21x 21x   7x       95x  
import { IDictionary } from '@zeedhi/core';
 
const uniqueBy = (a: IDictionary[], key: string) => {
	const seen: IDictionary = {};
	return a.filter((item) => {
		const k = item[key] || JSON.stringify(item);
		if (!seen[k]) {
			seen[k] = true;
			return true;
		}
		return false;
	});
};
 
export { uniqueBy };