Skip to content
Discussion options

You must be logged in to vote

@LPenny-github

你好 😊


這些 "index" 變數的命名選得不錯,對比分明,很好懂 👍

  • slowIndex, fastIndex
  • currentIndex, nextIndex

        bool currentDirection = inputNumbers[currentIndex] > 0;

這裡我會把 currentDirection 改成 isCurrentDirectionForward ;與出現在其它多處的 isForward 更有一致性 🤔

例如說,可以比較一下以下兩者的感覺

        if (isForward != isCurrentDirectionForward)

這讀起來是「如果 是向前 不等於 目前方向是向前」,是在比較兩個 bool 變數。

        if (isForward != currentDirection)

乍看之下可能會讀成「如果 是向前 不等於 目前的方向」。


        while (nextIndex < 0)
        {
            nextIndex += inputNumbers.Length;
        }
        nextIndex %= inputNumbers.Length;

這裡應該可以改寫成:

        if (nextIndex < 0)
        {
            nextIndex = inputNumbers.Length - -nextIndex % inputNumbers.Length;

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@LPenny-github
Comment options

@twy30
Comment options

@LPenny-github
Comment options

Answer selected by LPenny-github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants