Skip to content

Commit d5ef70b

Browse files
authored
Replace lodash.sum with native code (#2831)
1 parent 45c1080 commit d5ef70b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.changeset/giant-bulldogs-accept.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"victory-legend": patch
3+
---
4+
5+
Replace lodash sum with native code

packages/victory-legend/src/helper-methods.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defaults, groupBy, sum, range } from "lodash";
1+
import { defaults, groupBy, range } from "lodash";
22
import { Helpers, Style, TextSize } from "victory-core";
33
import { VictoryLegendProps } from "./victory-legend";
44

@@ -330,3 +330,19 @@ export const getBaseProps = (initialProps, fallbackProps) => {
330330
return childProps;
331331
}, initialChildProps);
332332
};
333+
334+
/**
335+
* Computes the sum of the values in `array`.
336+
* @param {Array} array The array to iterate over.
337+
* @returns {number} Returns the sum.
338+
*/
339+
function sum(array: number[]) {
340+
if (array && array.length) {
341+
let value = 0;
342+
for (let i = 0; i < array.length; i++) {
343+
value += array[i];
344+
}
345+
return value;
346+
}
347+
return 0;
348+
}

0 commit comments

Comments
 (0)