Skip to content

Commit e027a30

Browse files
committed
Fixed sum.js
1 parent 9df7c23 commit e027a30

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Sprint-1/implement/sum.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ function sum(elements) {
55

66
if (numbers.length === 0) return 0;
77

8-
const maxDecimalPlaces = numbers.reduce(
9-
(currMax, el) => Math.max(currMax, (String(el).split(".") || "").length),
10-
0
11-
);
12-
const decMultiplier = 10 ** maxDecimalPlaces;
13-
148
const total = numbers.reduce((acc, el) => acc + el, 0);
159

16-
return Math.round((total + Number.EPSILON) * decMultiplier) / decMultiplier;
10+
const decMultiplier = 100;
11+
12+
return Math.round(total * decMultiplier) / decMultiplier;
1713
}
1814

1915
module.exports = sum;

0 commit comments

Comments
 (0)