Find if a string starts and ends with another given string | JavaScript program to find if a given corner string is present at corners . ; If length of corner string is more , it cannot be present at corners . ; Return true if corner string is present at both corners of given string . ; Driver code
function isCornerPresent ( str , corner ) { var n = str . length ; var cl = corner . length ; if ( n < cl ) return false ; return ( str . substring ( 0 , cl ) . localeCompare ( corner ) === 0 && str . substring ( n - cl , n ) . localeCompare ( corner ) === 0 ) ; } var str = " " ; var corner = " " ; if ( isCornerPresent ( str , corner ) ) document . write ( " " ) ; else document . write ( " " ) ;