diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-02-15 12:35:02 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-02-15 12:35:02 +0530 |
commit | 9d3bea9f3ecb2da4563a8cf7f444f478f88e9c38 (patch) | |
tree | bd812414d948efb3ba38c9065facd1cc131449cc /modern/src/common | |
parent | 5970936c860285576848d170dd91bfcc488c941e (diff) | |
download | trackermap-web-9d3bea9f3ecb2da4563a8cf7f444f478f88e9c38.tar.gz trackermap-web-9d3bea9f3ecb2da4563a8cf7f444f478f88e9c38.tar.bz2 trackermap-web-9d3bea9f3ecb2da4563a8cf7f444f478f88e9c38.zip |
More Code Improvements
Diffstat (limited to 'modern/src/common')
-rw-r--r-- | modern/src/common/converter.js | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js index 26e2a82b..9cdc6239 100644 --- a/modern/src/common/converter.js +++ b/modern/src/common/converter.js @@ -1,47 +1,39 @@ -const speedConverter = (value, unit, back = false) => { - let factor; +const speedConverter = unit => { switch (unit) { case 'kmh': - factor = 1.852; - break; + return 1.852; case 'mph': - factor = 1.15078; - break; + return 1.15078; case 'kn': default: - factor = 1; + return 1; } - return back ? value / factor: value * factor; }; -const distanceConverter = (value, unit, back = false) => { - let factor; +const distanceConverter = unit => { switch (unit) { case 'mi': - factor = 0.000621371; - break; + return 0.000621371; case 'nmi': - factor = 0.000539957; - break; + return 0.000539957; case 'km': default: - factor = 0.001; - } - return back ? value / factor : value * factor; + return 0.001; + } } export const speedFromKnots = (value, unit) => { - return speedConverter(value, unit); + return value * speedConverter(unit); } export const speedToKnots = (value, unit) => { - return speedConverter(value, unit, true); + return value / speedConverter(unit); } export const distanceFromMeters = (value, unit) => { - return distanceConverter(value, unit); + return value * distanceConverter(unit); } export const distanceToMeters = (value, unit) => { - return distanceConverter(value, unit, true); + return value / distanceConverter(unit); } |