Skip to content

Commit

Permalink
Replace lodash.sum with native code (#2831)
Browse files Browse the repository at this point in the history
  • Loading branch information
carbonrobot committed Mar 13, 2024
1 parent 45c1080 commit d5ef70b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/giant-bulldogs-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"victory-legend": patch
---

Replace lodash sum with native code
18 changes: 17 additions & 1 deletion packages/victory-legend/src/helper-methods.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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;
}

0 comments on commit d5ef70b

Please sign in to comment.