FunctionRacerProblemsRace

Simplify Fraction

EasyMathPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems