Find the GCD of an array made up of numeric strings | Recursive function to return gcd of A and B ; Base case ; Length of A is greater ; Calculate GCD ; Store the GCD of the length of the Strings ; Driver Code ; Function call
function GCD ( lena , lenb ) { if ( lena == 0 ) return lenb ; if ( lenb == 0 ) return lena ; if ( lena == lenb ) return lena ; if ( lena > lenb ) return GCD ( lena - lenb , lenb ) ; return GCD ( lena , lenb - lena ) ; } function StringGCD ( a , b ) { let gcd = GCD ( a . length , b . length ) ; if ( a . substring ( 0 , gcd ) == ( b . substring ( 0 , gcd ) ) ) { let x = Math . floor ( b . length / gcd ) ; let y = Math . floor ( a . length / gcd ) ; let r = " " , s = " " ; while ( x -- > 0 ) s += a ; while ( y -- > 0 ) r += b ; if ( s == ( r ) ) return a . substring ( 0 , gcd ) ; } return " " ; } let a = " " ; let b = " " ; document . write ( StringGCD ( a , b ) ) ;