Skip to content

Commit

Permalink
fix: nan total amount bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Jan 8, 2024
1 parent d4c99d5 commit 8c37393
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app/common/math/calculate-averages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import BigNumber from 'bignumber.js';
import { calculateMeanAverage } from './calculate-averages';

describe(calculateMeanAverage.name, () => {
test('it calculates average of 0', () =>
expect(calculateMeanAverage([]).toString()).toEqual('0'));

test('it calculates averages of 1', () =>
expect(calculateMeanAverage([new BigNumber(1)]).toString()).toEqual('1'));

Expand Down
1 change: 1 addition & 0 deletions src/app/common/math/calculate-averages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import BigNumber from 'bignumber.js';
import { initBigNumber } from './helpers';

export function calculateMeanAverage(numbers: BigNumber[] | number[]) {
if (numbers.length === 0) return new BigNumber(0);
return numbers
.map(initBigNumber)
.reduce((acc, price) => acc.plus(price), new BigNumber(0))
Expand Down

0 comments on commit 8c37393

Please sign in to comment.