 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Repeated sum of Number’s digits in JavaScript
We are required to write a JavaScript function that recursively sums up the digits of a number until it reduces to a single digit number.
We are required to do so without converting the number to String or any other data type.
Therefore, let’s write the code for this function −
Example
The code for this will be −
const num = 546767643; const sumDigit = (num, sum = 0) => {    if(num){       return sumDigit(Math.floor(num / 10), sum + (num % 10));    }    return sum; }; const sumRepeatedly = num => {    while(num > 9){       num = sumDigit(num);    };    return num; }; console.log(sumRepeatedly(num));  Output
The output in the console will be −
3
Advertisements
 