[tor-commits] [atlas/master] Refactor the human readable bandwidth function

irl at torproject.org irl at torproject.org
Sat Apr 22 15:23:41 UTC 2017


commit ac485a5028de97112edcf3d032a6a65cf1f864ed
Author: cypherpunks <cypherpunks at torproject.org>
Date:   Fri Apr 21 14:50:40 2017 +0000

    Refactor the human readable bandwidth function
    
    The number of branches are reduced and the function returns early.
---
 js/helpers.js | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/js/helpers.js b/js/helpers.js
index 96a6296..0d50709 100644
--- a/js/helpers.js
+++ b/js/helpers.js
@@ -251,16 +251,14 @@ var CountryCodes = {
 function hrBandwidth(bw) {
     var bw_k = bw/1000;
     var bw_m = bw_k/1000;
+
     if (bw_m >= 1) {
-        bw = Math.round(bw_m*100)/100 + " MB/s";
-    } else {
-        if (bw_k >= 1) {
-            bw = Math.round(bw_k*100)/100 + " KB/s";
-        } else {
-            bw = bw + " B/s";
-        }
+        return Math.round(bw_m * 100) / 100 + " MB/s";
+    } else if (bw_k >= 1) {
+        return Math.round(bw_k * 100) / 100 + " KB/s";
     }
-    return bw;
+
+    return bw + " B/s";
 }
 
 function checkIfDataIsUpToDate(lastModifiedHeader) {





More information about the tor-commits mailing list