我们需要编写一个JavaScript函数,该函数接受一个数字并查找其所有数字的乘积。
如果该数字的任何数字为0,则应考虑该数字并将其乘以1。
例如:如果数字是-
5720
然后输出应为70。
因此,让我们为该函数编写代码-
为此的代码将是-
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));
输出结果
控制台中的输出将为-
70