We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9df7c23 commit e027a30Copy full SHA for e027a30
Sprint-1/implement/sum.js
@@ -5,15 +5,11 @@ function sum(elements) {
5
6
if (numbers.length === 0) return 0;
7
8
- const maxDecimalPlaces = numbers.reduce(
9
- (currMax, el) => Math.max(currMax, (String(el).split(".") || "").length),
10
- 0
11
- );
12
- const decMultiplier = 10 ** maxDecimalPlaces;
13
-
14
const total = numbers.reduce((acc, el) => acc + el, 0);
15
16
- return Math.round((total + Number.EPSILON) * decMultiplier) / decMultiplier;
+ const decMultiplier = 100;
+
+ return Math.round(total * decMultiplier) / decMultiplier;
17
}
18
19
module.exports = sum;
0 commit comments