322663 (2) [Avatar] Offline
#1
Page 28 beings by saying “it is inefficient having the [sic] loop over the same collection over and over every time you need an object. When faced with this problem, I always create an index...”

It seems that this approach might be valid in a language which offers true arrays. (By “true array,” I mean: an array whose members are all of the same data type and which can therefore be accessed directly, rather than through a sequential scan, in O(1) time via a numeric index value.) Because JavaScript doesn't offer such arrays, though, all you seem to be doing with your index substituting one data structure with O(n) performance for another.

Put another way: when you later access tempArray[someValue], JavaScript is going to have to loop through tempArray until it finds someValue. Whether you achieved a performance boost or a performance bust depends on the nature of your data.

It thus seems that indexing is a questionably-helpful distraction from the matter at hand: Angular.

Of course, please let me know if I'm missing anything.

Thank you,
Ben