← Back to challenges

Simplifying to Simplest Ratio

JavaScriptHardmathstringsnumbers

Instructions

Create a function which simplifies a given fraction into its simplest ratio. Return the fraction as a string.

Examples

simplifyFrac("2/4") ➞ "1/2"

simplifyFrac("15/25") ➞ "3/5"

simplifyFrac("4/9") ➞ "4/9"

Notes

  • Fractions are given as strings.
  • Return the same fraction if it is already in its simplified ratio (see example #3).
javascript
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.