adding sum helper

This commit is contained in:
rizky 2024-08-07 03:42:52 -07:00
parent 588061d732
commit 02564d8710
2 changed files with 10 additions and 1 deletions

View File

@ -1,10 +1,12 @@
export { FieldLoading } from "@/comps/ui/field-loading";
import { lazify, lazifyMany } from "@/utils/lazify";
import __get from "lodash.get";
import { sum } from "./utils/sum";
export { guessLabel } from "./utils/guess-label";
export { fetchLinkParams } from "./comps/form/field/type/TypeLink";
export { prasi_gen } from "./gen/prasi_gen";
export const _sum = sum;
export const _get = __get;
export const Accordion = lazify(

7
utils/sum.ts Executable file
View File

@ -0,0 +1,7 @@
import get from "lodash.get";
export const sum = (items: any[], keyName: string) => {
return items.reduce(function (a, b) {
return (Number(a) || 0) + (Number(get(b, keyName)) || 0);
}, 0);
};