You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
489 B
JavaScript
13 lines
489 B
JavaScript
9 years ago
|
function converter(toUnit, factor, offset, input) {
|
||
|
offset = offset || 0;
|
||
|
return [((offset+input)*factor).toFixed(2), toUnit].join(" ");
|
||
|
}
|
||
|
|
||
|
var milesToKm = converter.curry('km',1.60936,undefined);
|
||
|
var poundsToKg = converter.curry('kg',0.45460,undefined);
|
||
|
var farenheitToCelsius = converter.curry('degrees C',0.5556, -32);
|
||
|
|
||
|
milesToKm(10); // returns "16.09 km"
|
||
|
poundsToKg(2.5); // returns "1.14 kg"
|
||
|
farenheitToCelsius(98); // returns "36.67 degrees C"
|