From b47ac777a6bca9773078e747121a3e6476ec6107 Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Sat, 20 Jan 2024 12:47:33 +0100 Subject: [PATCH] refactoring: Avoided Duplication of Code in Function addFractions by utilizing the already implemented functions --- src/main/py/fractions.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/py/fractions.py b/src/main/py/fractions.py index 1a7f800..cb32529 100644 --- a/src/main/py/fractions.py +++ b/src/main/py/fractions.py @@ -16,13 +16,13 @@ def reduceFraction(num, denom): def addFractions(num1, denom1, num2, denom2): if denom1 != denom2: fractionExpansionFactor = lcm(denom1, denom2) - frac1Offset = fractionExpansionFactor / denom1 - frac2Offset = fractionExpansionFactor /denom2 - num1 *= frac1Offset - denom1 *= frac1Offset - num2 *= frac2Offset - denom2 *= frac2Offset - result_num = num1 + num2 + frac1Offset = divide(fractionExpansionFactor, denom1) + frac2Offset = divide(fractionExpansionFactor, denom2) + num1 = multiply(num1, frac1Offset) + denom1 = multiply(denom1, frac1Offset) + num2 = multiply(num2, frac2Offset) + denom2 = multiply(denom2, frac2Offset) + result_num = add(num1, num2) return reduceFraction(result_num, denom1) def multiplyFractions(num1, denom1, num2, denom2):