First N terms whose sum of digits is a multiple of 10 | Javascript Program to Find the Unique elements in linked lists ; Function to return the sum of digits of n ; Add last digit to the sum ; Remove last digit ; Function to return the nth term of the required series ; If sum of digit is already a multiple of 10 then append 0 ; To store the minimum digit that must be appended ; Return n after appending the required digit ; Function to print the first n terms of the required series ; Driver code
const TEN = 10 ; function digitSum ( n ) { let sum = 0 ; while ( n > 0 ) { sum += n % TEN ; n = Math . floor ( n / TEN ) ; } return sum ; } function getNthTerm ( n ) { let sum = digitSum ( n ) ; if ( sum % TEN == 0 ) return ( n * TEN ) ; let extra = TEN - ( sum % TEN ) ; return ( ( n * TEN ) + extra ) ; } function firstNTerms ( n ) { for ( let i = 1 ; i <= n ; i ++ ) document . write ( getNthTerm ( i ) + " " ) ; } let n = 10 ; firstNTerms ( n ) ;