
- 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
Recursive product of all digits of a number - JavaScript
We are required to write a JavaScript function that takes in a number and finds the product of all of its digits. If any digit of the number is 0, then it should be considered and multiplied as 1.
For example − If the number is 5720, then the output should be 70
Example
Following is the code −
const num = 5720; const recursiveProduct = (num, res = 1) => { if(num){ return recursiveProduct(Math.floor(num / 10), res * (num % 10 || 1)); } return res; }; console.log(recursiveProduct(num));
Output
This will produce the following output in console −
70
- Related Questions & Answers
- Recursive product of summed digits JavaScript
- Recursive sum all the digits of a number JavaScript
- Finding product of Number digits in JavaScript
- Product sum difference of digits of a number in JavaScript
- Largest product of n contiguous digits of a number in JavaScript
- Difference between product and sum of digits of a number in JavaScript
- Sorting digits of all the number of array - JavaScript
- Destructively Sum all the digits of a number in JavaScript
- Recursive sum of digits of a number formed by repeated appends in C++
- Recursive sum of digits of a number is prime or no in C++
- Separating digits of a number in JavaScript
- Returning number of digits in factorial of a number in JavaScript
- Digit sum upto a number of digits of a number in JavaScript
- Recursively adding digits of a number in JavaScript
- Prime digits sum of a number in JavaScript
Advertisements