Find max of two Rational numbers | JAVASCRIPT program to find max between two Rational numbers ; Get lcm of two number 's ; Get max rational number ; Find the LCM of first . denominator and sec . denominator ; Declare nume1 and nume2 for get the value of first numerator and second numerator ; Driver Code
class Rational { constructor ( nume , deno ) { this . nume = nume ; this . deno = deno ; } } function lcm ( a , b ) { return ( a * b ) / ( __gcd ( a , b ) ) ; } function maxRational ( first , sec ) { let k = lcm ( first . deno , sec . deno ) ; let nume1 = first . nume ; let nume2 = sec . nume ; nume1 *= k / ( first . deno ) ; nume2 *= k / ( sec . deno ) ; return ( nume2 < nume1 ) ? first : sec ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let first = new Rational ( 3 , 2 ) ; let sec = new Rational ( 3 , 4 ) ; let res = maxRational ( first , sec ) ; document . write ( res . nume + " " + res . deno ) ;