Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Last active May 15, 2021 21:30
Show Gist options
  • Save helabenkhalfallah/c8aed0b022b1f089fde06bdb9de9b7d1 to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/c8aed0b022b1f089fde06bdb9de9b7d1 to your computer and use it in GitHub Desktop.
JS Curried functions (1)
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