Check whether it is possible to convert A into B | Function that returns true if A can be converted to B with the given operations ; If the current number ends with 1 ; If the current number is divisible by 2 ; If above two conditions fail ; If it is possible to convert A to B ; Driver code
function canConvert ( a , b ) { while ( b > a ) { if ( b % 10 == 1 ) { b = parseInt ( b / 10 ) ; continue ; } if ( b % 2 == 0 ) { b = parseInt ( b / 2 ) ; continue ; } return false ; } if ( b == a ) return true ; return false ; } let A = 2 , B = 82 ; if ( canConvert ( A , B ) ) document . write ( " " ) ; else document . write ( " " ) ;