From b634aa581c1472a9b530f2607bbeff33278b693c Mon Sep 17 00:00:00 2001 From: Lcvieira2001 <114815013+Lcvieira2001@users.noreply.github.com> Date: Mon, 31 Oct 2022 13:37:48 -0300 Subject: [PATCH] conversion: liters to US gallons (#1255) --- Conversions/LitersToUSGallons.js | 11 +++++++++++ Conversions/test/LitersToUSGallons.test.js | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 Conversions/LitersToUSGallons.js create mode 100644 Conversions/test/LitersToUSGallons.test.js diff --git a/Conversions/LitersToUSGallons.js b/Conversions/LitersToUSGallons.js new file mode 100644 index 0000000000..62941a2c6d --- /dev/null +++ b/Conversions/LitersToUSGallons.js @@ -0,0 +1,11 @@ +/** + * This function converts liters to US gallons + * https://en.wikipedia.org/wiki/Gallon + * @constructor + * @param {number} liters - Amount of liters to convert to gallons + */ +const litersToUSGallons = (liters) => { + return liters / 3.785411784 +} + +export default litersToUSGallons diff --git a/Conversions/test/LitersToUSGallons.test.js b/Conversions/test/LitersToUSGallons.test.js new file mode 100644 index 0000000000..a1ad26b754 --- /dev/null +++ b/Conversions/test/LitersToUSGallons.test.js @@ -0,0 +1,5 @@ +import litersToUSGallons from '../LitersToUSGallons' + +test('Convert 50 liters to US gallons', () => { + expect(parseFloat(litersToUSGallons(50).toFixed(2))).toBe(13.21) +})