Skip to content

Commit

Permalink
fix 002_medium isPrime (forで書き直し)
Browse files Browse the repository at this point in the history
  • Loading branch information
yko-git committed Mar 16, 2024
1 parent 09d4a96 commit 5d3961f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions 003_practice/002_medium.js
Expand Up @@ -103,15 +103,12 @@ function isPalindrome(str) {
*
*/
function isPrime(num) {
//numが2桁以上の場合
if (num.length >= 2) {
num = Array.from(String(num), Number);
for (let i = 0; i < num.length; i++) {
num = num[i] + num[i + 1];
}
//numが2の場合
if (num === 1) {
return false;
}
for (let i = 0; i <= num; i++) {
if (num % i === 0 || num === 1 || num === 2) {
for (let i = 2; i < num; i++) {
if (num % i === 0) {
return false;
}
}
Expand Down

0 comments on commit 5d3961f

Please sign in to comment.