

- 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
Finding product of Number digits in 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.
Therefore, let’s write the code for this function −
Example
The code for this will be −
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
The output in the console will be −
70
- Related Questions & Answers
- Recursive product of all digits of a number - JavaScript
- Product sum difference of digits of a number in JavaScript
- Largest product of n contiguous digits of a number in JavaScript
- Recursive product of summed digits JavaScript
- Difference between product and sum of digits of a number in JavaScript
- JavaScript: Finding nearest prime number greater or equal to sum of digits - JavaScript
- Finding the just bigger number formed by same digits in JavaScript
- Finding product of an array using recursion in JavaScript
- Finding persistence of number in JavaScript
- Finding the immediate bigger number formed with the same digits in JavaScript
- Finding the product of array elements with reduce() in JavaScript
- Finding the Largest Triple Product Array in JavaScript
- Separating digits of a number in JavaScript
- Largest product of contiguous digits in Python
- Finding Gapful number in JavaScript
Advertisements