From 02564d871071c8f68323a79ef444e142b932078b Mon Sep 17 00:00:00 2001 From: rizky Date: Wed, 7 Aug 2024 03:42:52 -0700 Subject: [PATCH] adding sum helper --- exports.tsx | 4 +++- utils/sum.ts | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100755 utils/sum.ts diff --git a/exports.tsx b/exports.tsx index d3e5d83..1e2ad49 100755 --- a/exports.tsx +++ b/exports.tsx @@ -1,13 +1,15 @@ 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( +export const Accordion = lazify( async () => (await import("@/comps/ui/accordion")).Accordion ); diff --git a/utils/sum.ts b/utils/sum.ts new file mode 100755 index 0000000..588ab27 --- /dev/null +++ b/utils/sum.ts @@ -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); +};