Skip to content

Commit b2a5048

Browse files
refactor: simplify BMI calculation by removing unnecessary string conversion
1 parent ad3dfa9 commit b2a5048

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
function calculateBMI(weight, height) {
1818
let sqh = height * height;
1919
let bmi = weight / sqh;
20-
let bmiS = bmi.toString();
2120

22-
if (bmiS.includes(".")) {
23-
let dotBmiS = bmiS.indexOf(".");
24-
return Number(bmiS.slice(0, dotBmiS + 2));
25-
}
26-
return bmi;
21+
return bmi.toFixed(1);
2722
}
2823
console.log(calculateBMI(20, 1.79));

0 commit comments

Comments
 (0)