Fix variable naming and bounds check in displayRate function

This commit is contained in:
Igor Kulman
2025-09-21 22:22:32 +02:00
committed by Bastien Wirtz
parent 06b677ab76
commit 5b29bc411c

View File

@@ -35,16 +35,16 @@ const units = ["B", "KB", "MB", "GB"];
// value for which we have a unit is determined. Return the value with
// up to two decimals as a string and unit/s appended.
const displayRate = (rate) => {
let i = 0;
let unitIndex = 0;
while (rate > 1000 && i < units.length) {
while (rate > 1000 && unitIndex < units.length - 1) {
rate /= 1000;
i++;
unitIndex++;
}
return (
Intl.NumberFormat(undefined, { maximumFractionDigits: 2 }).format(
rate || 0,
) + ` ${units[i]}/s`
) + ` ${units[unitIndex]}/s`
);
};