Check if a number ends with another number or not | Function to check if B is a suffix of A or not ; Find the number of digit in B ; Subtract B from A ; Returns true , if B is a suffix of A ; Given numbers ; Function call ; If B is a suffix of A , then print " Yes "
function checkSuffix ( A , B ) { let digit_B = parseInt ( Math . log10 ( B ) + 1 , 10 ) ; A -= B ; return ( A % ( Math . pow ( 10 , digit_B ) ) > 0 ) ; } let A = 12345 , B = 45 ; let result = checkSuffix ( A , B ) ; if ( ! result ) { document . write ( " " ) ; } else { document . write ( " " ) ; }