twenty / packages /twenty-shared /src /utils /array /sumByProperty.ts
Jules
Initial clean CRM deployment with prebuilt assets
d9494a5
Raw
History Blame Contribute Delete
392 Bytes
import { isNumberOrNaN } from '@sniptt/guards';
export const sumByProperty = <T, K extends keyof T>(property: K) => {
return (accumulator: number, nextItem: T) => {
if (typeof accumulator !== 'number') {
accumulator = 0;
}
if (!isNumberOrNaN(nextItem[property])) {
return accumulator;
}
accumulator += nextItem[property];
return accumulator;
};
};