mercredi 15 juin 2016

Performance of array reverse in ActionScript 3

I have two code snippets . which one is better.

var texts:Array = new Array(1,2,3,4,5,6,7,8,9,10);
texts.reverse();
for(var index:int=0; index < texts.length; index++) {
    trace(texts[index]);
}

Or

var texts:Array = new Array(1,2,3,4,5,6,7,8,9,10);
for( var index:int = texts.length; --index;) {
      trace(texts[index]);
}

In former we have reverse operation and then print it and in latter we start from the length and start printing the array. The goal is to traverse the array from last.

Aucun commentaire:

Enregistrer un commentaire