Number of common base strings for two strings | function for finding common divisor ; Checking if ' base ' is base String of ' s1' ; Checking if ' base ' is base String of ' s2' ; Driver code
function isCommonBase ( base , s1 , s2 ) { for ( let j = 0 ; j < s1 . length ; ++ j ) { if ( base [ j % base . length ] != s1 [ j ] ) { return false ; } } for ( let j = 0 ; j < s2 . length ; ++ j ) { if ( base [ j % base . length ] != s2 [ j ] ) { return false ; } } return true ; } function countCommonBases ( s1 , s2 ) { let n1 = s1 . length , n2 = s2 . length ; let count = 0 ; for ( let i = 1 ; i <= Math . min ( n1 , n2 ) ; i ++ ) { let base = s1 . substring ( 0 , i ) ; if ( isCommonBase ( base , s1 , s2 ) ) { count ++ ; } } return count ; } let s1 = " " ; let s2 = " " ; document . write ( countCommonBases ( s1 , s2 ) ) ;