Skip to content

Commit

Permalink
Update PrimeNumbers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kouhei-1 authored Nov 11, 2024
1 parent f405d00 commit 2c17a49
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions limited/PrimeNumbers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function generatePrimeNumbers() {
// 区切り文字を設定
// 以下区切り文字
const delimiter_select = document.getElementById("delimiter").value;
let delimiter_txt;

if (delimiter_select === "enter") {
delimiter_txt = "\n";
} else {
Expand All @@ -12,6 +13,13 @@ function generatePrimeNumbers() {
const primes = Array(upperLimit + 1).fill(true);
primes[0] = primes[1] = false;

// エラーチェック: 上限値が入力されていない場合
if (isNaN(upperLimit) || upperLimit <= 1) {
alert("有効な上限値を入力してください");
return;
}

// エラーチェック: 上限値が数値に変換できなかった場合
for (let p = 2; p * p <= upperLimit; p++) {
if (primes[p]) {
for (let i = p * p; i <= upperLimit; i += p) {
Expand All @@ -31,8 +39,8 @@ function generatePrimeNumbers() {
const csvContent = primeNumbers.join(delimiter_txt);

// ダウンロードリンクの作成
const downloadLink = document.createElement('a');
const downloadLink = document.getElementById("downloadLink");
downloadLink.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csvContent);
downloadLink.download = 'primeNumbers.csv';
downloadLink.style.display = 'inline'; // ダウンロードリンクを表示
downloadLink.click();
}

0 comments on commit 2c17a49

Please sign in to comment.