Junction Numbers | Function to find the sum Of digits of N ; To store sum of N and sumOfdigitsof ( N ) ; extracting digit ; Function to check Junction numbers ; To store count of ways n can be represented as i + SOD ( i ) ; Driver Code ; Function Call
function sum ( n ) { let sum = 0 ; while ( n != 0 ) { let r = n % 10 ; sum = sum + r ; n = parseInt ( n / 10 ) ; } return sum ; } function isJunction ( n ) { let count = 0 ; for ( i = 1 ; i <= n ; i ++ ) { if ( i + sum ( i ) == n ) count ++ ; } return count >= 2 ; } let N = 111 ; if ( isJunction ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;