The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

322663 (2) [Avatar] Offline
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,