Iterator Helpers: arr.slice(10, 20).filter(el => el < 10).map(el => el + 5)
> This is really inefficient because for each transformation a new array should be allocated..slice[0] does not allocate, nor does .filter[1], only map does.. so one allocation. arr.values().drop(10).take(10).filter(el => el < 10).map(el => el + 5).toArray()
Allocates once for .values[2], and again for .toArray[3].. there's decreased efficiency here.Swapping variables: Only do this if you don't care about performance (the advice is written like using the array swap hack is categorically better). [0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... [3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... |
However, when it does, it should be explicitly recognised, appropriate boundaries put, and that code written in a completely different style altogether. There are A LOT more of idiomatic and widespread JS/TS patterns that should not be used in such code.
Before TS, I used to write games in C# (Unity), and it was the same there too. I think this distinction between two kinds of code holds in a lot of environments.