Spaces:
Build error
Build error
File size: 392 Bytes
d9494a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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;
};
};
|