Check if a string is concatenation of another given string | Function to check if a String is concatenation of another String ; Stores the length of str2 ; Stores the length of str1 ; If M is not multiple of N ; Traverse both the Strings ; If str1 is not concatenation of str2 ; Driver Code
function checkConcat ( str1 , str2 ) { let N = str1 . length ; let M = str2 . length ; if ( N % M != 0 ) { return false ; } for ( let i = 0 ; i < N ; i ++ ) { if ( str1 [ i ] != str2 [ i % M ] ) { return false ; } } return true ; } let str1 = " " ; let str2 = " " ; if ( checkConcat ( str1 , str2 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }