[GH-ISSUE #42] The loop's condition feels off #17

Closed
opened 2026-03-02 02:53:02 +03:00 by kerem · 3 comments
Owner

Originally created by @djalilhebal on GitHub (Oct 23, 2023).
Original GitHub issue: https://github.com/artiebits/fake-git-history/issues/42

First of all, nice utility.

I just checked its source code and the loop's condition felt off.
The end result will be fine (always < max commits per day), but it seems as if it's "changing its mind"...
Imagine the following execution of i < getRandomIntInclusive(0, 2):

  1. First iteration: 0 < 1
  2. Second iteration: 1 < 2
  3. Third iteration: 2 < 0

A simple edit should make the intention clearer:

-    for (let i = 0; i < getRandomIntInclusive(...commitsPerDay); i++) {
+    const commitsCount = getRandomIntInclusive(...commitsPerDay);
+    for (let i = 0; i < commitsCount; i++) {
Originally created by @djalilhebal on GitHub (Oct 23, 2023). Original GitHub issue: https://github.com/artiebits/fake-git-history/issues/42 First of all, nice utility. I just checked its source code and the loop's condition felt off. The end result will be fine (always < max commits per day), but it seems as if it's "changing its mind"... Imagine the following execution of `i < getRandomIntInclusive(0, 2)`: 1. First iteration: `0 < 1` 2. Second iteration: `1 < 2` 3. Third iteration: `2 < 0` A simple edit should make the intention clearer: ```diff - for (let i = 0; i < getRandomIntInclusive(...commitsPerDay); i++) { + const commitsCount = getRandomIntInclusive(...commitsPerDay); + for (let i = 0; i < commitsCount; i++) { ```
kerem closed this issue 2026-03-02 02:53:02 +03:00
Author
Owner

@smcnary commented on GitHub (Oct 23, 2023):

Is the list on the my-history file supposed to be 1 entry or all the entries? Because on mine it's just the last entry in the block.

<!-- gh-comment-id:1775543267 --> @smcnary commented on GitHub (Oct 23, 2023): Is the list on the my-history file supposed to be 1 entry or all the entries? Because on mine it's just the last entry in the block.
Author
Owner

@artiebits commented on GitHub (Oct 23, 2023):

hi @djalilhebal,

a good catch, because it's actually a bug. indeed, the getRandomIntInclusive is being called on every iteration of the for loop. feel free to open a PR and fix it!

<!-- gh-comment-id:1775605903 --> @artiebits commented on GitHub (Oct 23, 2023): hi @djalilhebal, a good catch, because it's actually a bug. indeed, the `getRandomIntInclusive` is being called on every iteration of the for loop. feel free to open a PR and fix it!
Author
Owner

@artiebits commented on GitHub (Oct 29, 2023):

solved in #43

<!-- gh-comment-id:1784167315 --> @artiebits commented on GitHub (Oct 29, 2023): solved in #43
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-git-history#17
No description provided.