even shorter

52                  for (var i in a) {
53                      if (!a.hasOwnProperty(i) || !equiv(a[i],
b[i])) {
54                        return false;
55                      }
56                  }

On 21 Okt., 19:07, "markus.staab" <[EMAIL PROTECTED]> wrote:
> taking a second look at the for (x in y) loops, we could also do some
> further optimization:
>
> 52                  for (var i in a) {
> 53                      if (a.hasOwnProperty(i)) {
> 54                          if(!equiv(a[i], b[i]))
>                                return false;
> 55                      } else {
>                             return false;
>                          }
> 56                  }
>
> markus.staab schrieb:
>
> > in reply to the article athttp://philrathe.com/articles/equiv:
>
> > in the equiv method there is several times a loop like
>
> > 34             for (var i = 0; i < len; i++) {
> > 35                 eq = eq && equiv(a[i], b[i]);
> > 36             }
> > 37             return eq;
>
> > this could be optimized, because if one of the elements is not equal,
> > you found, that the origin elements aren't equal..
>
> > so better use
>
> > 34             for (var i = 0; i < len && eq; i++) {
> > 35                 eq = eq && equiv(a[i], b[i]);
> > 36             }
> > 37             return eq;
>
> > see the additional abort condition in the for loop...
> > This little "trick" could be applied in several places of the
> > function, e.g.
>
> > 52             for (var i in a) {
> > 53                 if (a.hasOwnProperty(i)) {
> > 54                     eq = eq && equiv(a[i], b[i]);
> > 55                 }
> > 56             }
>
> > 59             for (var i in b) {
> > 60                 if (b.hasOwnProperty(i)) {
> > 61                     eq = eq && equiv(b[i], a[i]);
> > 62                 }
> > 63             }
>
> > in the for(x in y) there should be a break, since there is no abort
> > condition.
>
> > greets, markus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to