From d5ef70b9147c4950ef448490f0738ff4b865928b Mon Sep 17 00:00:00 2001 From: Charlie Brown Date: Wed, 13 Mar 2024 07:39:36 -0500 Subject: [PATCH] Replace lodash.sum with native code (#2831) --- .changeset/giant-bulldogs-accept.md | 5 +++++ packages/victory-legend/src/helper-methods.ts | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/giant-bulldogs-accept.md diff --git a/.changeset/giant-bulldogs-accept.md b/.changeset/giant-bulldogs-accept.md new file mode 100644 index 000000000..9d15512a0 --- /dev/null +++ b/.changeset/giant-bulldogs-accept.md @@ -0,0 +1,5 @@ +--- +"victory-legend": patch +--- + +Replace lodash sum with native code diff --git a/packages/victory-legend/src/helper-methods.ts b/packages/victory-legend/src/helper-methods.ts index badbc172c..f149f7f59 100644 --- a/packages/victory-legend/src/helper-methods.ts +++ b/packages/victory-legend/src/helper-methods.ts @@ -1,4 +1,4 @@ -import { defaults, groupBy, sum, range } from "lodash"; +import { defaults, groupBy, range } from "lodash"; import { Helpers, Style, TextSize } from "victory-core"; import { VictoryLegendProps } from "./victory-legend"; @@ -330,3 +330,19 @@ export const getBaseProps = (initialProps, fallbackProps) => { return childProps; }, initialChildProps); }; + +/** + * Computes the sum of the values in `array`. + * @param {Array} array The array to iterate over. + * @returns {number} Returns the sum. + */ +function sum(array: number[]) { + if (array && array.length) { + let value = 0; + for (let i = 0; i < array.length; i++) { + value += array[i]; + } + return value; + } + return 0; +}