<i>Iterator Helpers:</i><p><pre><code> arr.slice(10, 20).filter(el => el < 10).map(el => el + 5)
</code></pre>
> This is really inefficient because for each transformation a new array should be allocated.<p>.slice[0] does not allocate, nor does .filter[1], only map does.. so one allocation.<p><pre><code> arr.values().drop(10).take(10).filter(el => el < 10).map(el => el + 5).toArray()
</code></pre>
Allocates once for .values[2], and again for .toArray[3].. there's decreased efficiency here.<p><i>Swapping variables</i>:<p>Only do this if you don't care about performance (the advice is written like using the array swap hack is categorically better).<p>[0]: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a><p>[1]: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a><p>[2]: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a><p>[3]: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/toArray" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a>