数字所有数字的递归乘积 - JavaScript
javascriptweb developmentfront end technologyobject oriented programming更新于 2025/12/15 11:56:17
我们需要编写一个 JavaScript 函数,该函数接受一个数字并找到其所有数字的乘积。如果数字的任何数字为 0,则应将其视为 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
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

