-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuel-consumption.js
48 lines (41 loc) · 1.17 KB
/
fuel-consumption.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(function(angular){ 'use strict';
angular.module('conversions.fuel', [])
.factory('conversionsFuel', ['$log', function($log){
return {
//=========
// !Errors
//=========
amtTypeError: function(amt){
$log.error(amt+' is not a number and cannot be converted');
return NaN;
},
//====================
// !Fuel consumption Conversions
//====================
mpgUsToMpgImp: function(amt){
if(isNaN(amt)) return this.amtTypeError(amt);
return amt * 1.20095;
},
mpgUsToKmPerLiter: function(amt){
if(isNaN(amt)) return this.amtTypeError(amt);
return amt * 0.425144;
},
mpgImpToMpgUs: function(amt){
if(isNaN(amt)) return this.amtTypeError(amt);
return amt * 0.832674;
},
mpgImpToKmPerLiter: function(amt){
if(isNaN(amt)) return this.amtTypeError(amt);
return amt * 0.354006;
},
kmPerLiterToMpgUs: function(amt){
if(isNaN(amt)) return this.amtTypeError(amt);
return amt * 2.35215;
},
kmPerLiterToMpgImp: function(amt){
if(isNaN(amt)) return this.amtTypeError(amt);
return amt * 2.82481;
}
};
}]);
})(window.angular);