- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- 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

# Sum up a number until it becomes one digit - 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. Do it without converting the number to String or any other data type.

## Example

Following is the code −

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

This will produce the following output in console −

3

- Related Questions & Answers
- Sum up a number until it becomes 1 digit JavaScript
- Summing up all the digits of a number until the sum is one digit in JavaScript
- Finding sum of digits of a number until sum becomes single digit in C++
- C++ program to find sum of digits of a number until sum becomes single digit
- Program to find sum of digits until it is one digit number in Python
- Reduce sum of digits recursively down to a one-digit number JavaScript
- Negative number digit sum in JavaScript
- Digit sum upto a number of digits of a number in JavaScript
- Python program to Remove and print every third from list until it becomes empty?
- Maximum of sum and product of digits until number is reduced to a single digit in C++
- Check whether sum of digit of a number is Palindrome - JavaScript
- Number of Digit One in C++
- Smallest number formed by shuffling one digit at most in JavaScript
- Checking digit sum of smallest number in the array in JavaScript
- Square every digit of a number - JavaScript

Advertisements