Created
May 15, 2021 21:41
-
-
Save helabenkhalfallah/3e4643eb5b268f323fc9a90137112c9c to your computer and use it in GitHub Desktop.
JS Curried Function (Converter)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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