Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save helabenkhalfallah/3e4643eb5b268f323fc9a90137112c9c to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/3e4643eb5b268f323fc9a90137112c9c to your computer and use it in GitHub Desktop.
JS Curried Function (Converter)
const converterOld = (toUnit, factor, offset, input) => {
const converterOffset = offset || 0;
return [((converterOffset + input) * factor).toFixed(2), toUnit].join(' ');
};
const convert10MilesToKm = converterOld('km', 1.60936, undefined, 10);
const convert20MilesToKm = converterOld('km', 1.60936, undefined, 20);
const convert30MilesToKm = converterOld('km', 1.60936, undefined, 30);
console.log('convert10MilesToKm : ', convert10MilesToKm); // "16.09 km"
console.log('convert20MilesToKm : ', convert20MilesToKm); // "32.19 km"
console.log('convert30MilesToKm : ', convert30MilesToKm); // "48.28 km"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment