squareRoot(6) returns 3, squareRoot(12) returns 4; test expects squareRoot(3, 1) = 1.8 (correct: 1.7)
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
- 領域
- testing-qa
調査の方向性
まず src/algorithms/math/square-root/squareRoot.js と、squareRoot.test.js:30 にある失敗する期待値を確認し、ループの停止条件を issue の例と比較してください。平方根のテストを実行し、squareRoot(3, 1) を含む、列挙された入力を確認してください。結果が正しく丸められ、#2187 で報告されたハングが解消されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
src/algorithms/math/square-root/squareRoot.js stops Newton's iteration when |number - root²| <= 10^-tolerance (line 31). That bounds the error of the square, not of the root. Newton's method approaches √n from above, so the loop stops on an overestimate, and rounding then goes the wrong way.
squareRoot(6); // 3 expected 2 (√6 = 2.449)
squareRoot(12); // 4 expected 3 (√12 = 3.464)
squareRoot(3, 1); // 1.8 expected 1.7 (√3 = 1.732)
squareRoot.test.js:30 asserts expect(squareRoot(3, 1)).toBe(1.8), so the test enshrines the bug. For n = 0..3000 and tolerance 0..6 there are 68 wrong results.
Fix: iterate until the root stops decreasing (while (next < root)), then round. Checked on 259,695 inputs against correctly rounded Math.sqrt; the only mismatches are 53 last-digit float effects at tolerance >= 10. This also removes the hang reported in #2187 (squareRoot(65549, 11)). The #2187 change alone still returns 3 and 1.8.
Found during an independent property-based audit of this repo (full report and reproducible harness: https://github.com/devladpopov/algorithm-autopsy/tree/main/autopsy-02).
- 主要言語
- JavaScript
- スター
- 197k
- フォーク
- 31k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
trekhleb/javascript-algorithms のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
trekhleb/javascript-algorithms#2225 ·
-
BinarySearchTreeNode removing対応中かも @bbonch が 260 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
trekhleb/javascript-algorithms#2102 · コメント 1 件 ·
-
math: uniquePaths and leastCommonMultiple return non-integers below 2^53; iterative Euclid is subtraction-based and can hang対応中かも @Shubham-Padkonde が 3 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
trekhleb/javascript-algorithms#2238 ·
-
Trie.deleteWord fails for words containing characters outside the BMP (e.g. emoji)対応中かも @Shubham-Padkonde が 3 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 35/100
trekhleb/javascript-algorithms#2237 ·
-
bellmanFord: runs in O(V²·E) rather than the O(V·E) / O(E) stated in README対応中かも @Shubham-Padkonde が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
trekhleb/javascript-algorithms#2236 ·
trekhleb/javascript-algorithms の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
apex-dev-tools/apex-log-parser#199 ·
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue hacktoberfest help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
ReadBufferStream.addBuffer adds the full ArrayBuffer of a typed array view, and ignores its byteOffset対応中かも @wayfarer3130 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Expo 57 example: pnpm install fails with ERR_PNPM_TRUST_DOWNGRADE対応中かも @github-actions が今日担当しました。 オープンbug react-native team/client-libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
PostHog/posthog-js#5442 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信