Astonishing Numbers | Function to concatenate two integers into one ; Convert both the integers to string ; Concatenate both strings ; Convert the concatenated string to integer ; return the formed integer ; Function to check if N is a Astonishing number ; Loop to find sum of all integers from i till the sum becomes >= n ; variable to store sum of all integers from i to j and check if sum and concatenation equals n or not ; finding concatenation of i and j ; condition for Astonishing number ; Given Number ; Function Call
function concat ( a , b ) { var s1 = a . toString ( ) ; var s2 = b . toString ( ) ; var s = s1 + s2 ; var c = s ; return c ; } function isAstonishing ( n ) { for ( var i = 1 ; i < n ; i ++ ) { var sum = 0 ; for ( var j = i ; j < n ; j ++ ) { sum += j ; if ( sum == n ) { var concatenation = concat ( i , j ) ; if ( concatenation == n ) { return true ; } } } } return false ; } var n = 429 ; if ( isAstonishing ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;