Simplify Fraction
Reduce the fraction numerator / denominator to lowest terms and return it as the list [numerator, denominator]. The denominator in the result must be positive, so a negative fraction carries its sign on the numerator. A numerator of 0 gives [0, 1].
Example 1
numerator 6
denominator 8
returns [3,4]
Divide both by 2: 3/4.
Example 2
numerator 5
denominator -10
returns [-1,2]
Becomes -1/2.
Constraints
-1000 <= numerator <= 1000denominatoris not 0 and-1000 <= denominator <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Triangle Area From PointsEasy
- Ugly NumberEasy
- Water BottlesEasy
- Balanced Parentheses CountMedium
- Convert to Base Minus TwoMedium
- Count Numbers With Unique DigitsMedium
- Count PrimesMedium
- Day of the WeekMedium