JavaScript 中的 Pronic 数
javascriptweb developmentfront end technologyobject oriented programming更新于 2025/11/24 19:24:17
Pronic 数是两个连续整数的乘积,即形式为 n(n + 1) 的数。
我们需要编写一个 JavaScript 函数,该函数接受一个数字,如果该数字是 Pronic 数,则返回 true,否则返回 false
让我们来编写该函数的代码 −
示例
const num = 90;
const isPronic = num => {
let nearestSqrt = Math.floor(Math.sqrt(num)) - 1;
while(nearestSqrt * (nearestSqrt + 1) <= num){
if(nearestSqrt * (nearestSqrt+1) === num ){
return true;
};
nearestSqrt++;
};
return false;
};
console.log(isPronic(num));
输出
以下是控制台中的输出 −
true
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

