Is not arithmetic shift better in countSetBits.js?
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 38/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript
- 領域
- tooling
調査の方向性
Start in countSetBits.js at the shift on the line using >>>= 1. Read the surrounding function and any nearby tests or documentation to determine the intended behavior for negative numbers. Done means the shift behavior is explicitly settled and the implementation and relevant tests consistently reflect that decision.
索引モデルが issue の本文から書いたものです。
説明
The file countSetBits.js has the function:
/**
* @param {number} originalNumber
* @return {number}
*/
export default function countSetBits(originalNumber) {
let setBitsCount = 0;
let number = originalNumber;
while (number) {
// Add last bit of the number to the sum of set bits.
setBitsCount += number & 1;
// Shift number right by one bit to investigate other bits.
number >>>= 1;
}
return setBitsCount;
}
I wonder if it wouldn't be better to use an arithmetic shift on line number >>>= 1 instead of a logical shift, thus preserving the sign of the number.
- 主要言語
- 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 が 245 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
trekhleb/javascript-algorithms#2102 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
trekhleb/javascript-algorithms#2221 · コメント 4 件 ·
-
zh-TW translations missing — should contributors help complete?対応中かも @anees4500 が 336 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
trekhleb/javascript-algorithms#2085 · コメント 6 件 · リアクション 1 件 ·
-
LinkedList methods.オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
trekhleb/javascript-algorithms#2065 · コメント 1 件 ·
trekhleb/javascript-algorithms の issue をすべて見る
似ている issue
-
Progress difficulty filter lists Hard before Medium対応中かも @Pandamachi が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
sysprog21/codetrial#281 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 71/100
yjh051108/dsh-routing-suite#227 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
needs-triage release-watch
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
remoteintech/remote-jobs#2271 ·
メンテナーはふだん 1 日以内に返信