Simplified Fractions

Published by supafly in

Create a function that returns the simplified version of a fraction.

Examples

Simplify("4/6") ➞ "2/3"

Simplify("10/11") ➞ "10/11"

Simplify("100/400") ➞ "1/4"

Simplify("8/4") ➞ "2"

Notes

  • A fraction is simplified if there are no common factors (except 1) between the numerator and the denominator. For example, 4/6 is not simplified, since 4 and 6 both share 2 as a factor.
  • If improper fractions can be transformed into integers, do so in your code (see example #4).
Watch a quick demo on how Edabit works.