mgechev / javascript-algorithms

💻 JavaScript implementations of computer science algorithms
https://mgechev.github.io/javascript-algorithms/
MIT License
7.83k stars 1.27k forks source link

Suboptimal for loop(s) #149

Closed rthangam closed 5 years ago

rthangam commented 5 years ago

In most of the code array.length is checked in the for loop. Since this is just a sample code and data set is not much it is ok, but i guess it is suboptimal since the array.length value will be calculated everytime the index value is checked. so instead that we can store it in a variable and use it ?.

mgechev commented 5 years ago

array.length is retrieved with O(1), caching the value is not necessary.