Skip to content

Commit

Permalink
Merge pull request #318 from rotelloj/patch-1
Browse files Browse the repository at this point in the history
Update array-foreach.md
  • Loading branch information
koddsson committed Sep 30, 2022
2 parents 2c442af + a235e77 commit 73857ca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/rules/array-foreach.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The problem we now have is that we're iterating multiple times over the items in
}
```

Changing isn't always necessarily bad. Chaining can advertise a series of transformations that are independent from one another, and therefore aid readability. Additionally, sometimes the "goto-style" behavior of `continue` in for loops can hamper readability. For small Arrays, performance is not going to be of concern, but caution should be applied where there is a potentially unbounded Array (such as iterating over a fetched users list) as performance can easily become a bottleneck when unchecked.
Chaining isn't always necessarily bad. Chaining can advertise a series of transformations that are independent from one another, and therefore aid readability. Additionally, sometimes the "goto-style" behavior of `continue` in for loops can hamper readability. For small Arrays, performance is not going to be of concern, but caution should be applied where there is a potentially unbounded Array (such as iterating over a fetched users list) as performance can easily become a bottleneck when unchecked.

The `forEach` method passes more than just the current item it is iterating over. The signature of the `forEach` callback method is `(cur: T, i: Number, all: []T) => void` and it can _additionally_ override the `receiver` (`this` value), meaning that often the _intent_ of what the callback does is hidden. To put this another way, there is _no way_ to know what the following code operates on without reading the implementation: `forEach(polishApple)`.

Expand Down

0 comments on commit 73857ca

Please sign in to comment.