Check length of a string is equal to the number appended at its last | Function to find if given number is equal to length or not ; Traverse string from end and find the number stored at the end . x is used to store power of 10. ; Check if number is equal to string length except that number 's digits ; Driver code
function isequal ( str ) { let n = str . length ; let num = 0 , x = 1 , i = n - 1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( ' ' <= str [ i ] && str [ i ] <= ' ' ) { num = ( str [ i ] - ' ' ) * x + num ; x = x * 10 ; if ( num >= n ) return false ; } else break ; } return num == i + 1 ; } let str = " " ; if ( isequal ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;