题解 | 判断质数

判断质数

https://www.nowcoder.com/practice/b936f737e2b34b3199a7c875446edd06

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
    </head>
    <body>
        <script type="text/javascript">
        	// 补全代码
        	// 质数(Prime Number),又称素数,是指在大于 1 的自然数中,除了 1 和它本身以外,不能被其他自然数整除的数。
            Number.prototype._isPrime = function() {
                if (this <= 1) return false;
                for (let i = 2; i < this; i++) {
                    if (this % i === 0) {
                        return false;
                    }
                }
                return true;
            }

            console.log((2).isPrime());
            
        </script>
    </body>
</html>

全部评论

相关推荐

01-19 12:48
门头沟学院 C++
只想搞钱的鸽子很喜欢...:混账是很多的,还有那些在自己风华正茂的年纪说风凉话讥讽那些下岗前员工的。这些人都是现在职场环境这么烂的帮凶
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务