JSFiddle - React, Tailwind, and code Playground
by orchid1
HTML
<iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/orchid1/BdR5L/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
JavaScript
//create the curry function as part of the prototype
Function.prototype.curry = function() {
if (arguments.length < 1) {
return this;
}
var __method = this;
var args = [].slice.call(arguments);
return function() {
return __method.apply(this, args.concat([].slice.apply(arguments)));
};
};
//the base function we will be using to get the curried function
function converter(toUnit, factor, offset, input) {
offset = offset || 0;
return ((offset + input) * factor).toFixed(2) + ' ' + toUnit;
}
//getting the curried function
var milesToKm = converter.curry('km', 1.60936, undefined);
var poundsToKg = converter.curry('kg', 0.45460, undefined);
var fahrenheitToCelsius = converter.curry('degrees C', 0.5556, -32);
//applying the curry function
alert(milesToKm(10)); // returns "16.09 km"
alert(poundsToKg(2.5)); // returns "1.14 kg"
alert(fahrenheitToCelsius(98)); // returns "36.67 degrees C"