Posted By

adrianparr on 03/05/10


Tagged

beginning array length move pop as3 end Put unshift


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 Put Last Item of Array at the Beginning


 / Published in: ActionScript 3
 

  1. function putLastItemOfArrayAtBeginning($a:Array):Array
  2. {
  3. $a.unshift($a[$a.length-1]);
  4. $a.pop();
  5. return $a;
  6. }
  7.  
  8. var myArray:Array = new Array(0,1,2,3,4,5);
  9. trace(myArray);
  10. myArray = putLastItemOfArrayAtBeginning(myArray);
  11. trace(myArray);
  12. myArray = putLastItemOfArrayAtBeginning(myArray);
  13. trace(myArray);
  14. myArray = putLastItemOfArrayAtBeginning(myArray);
  15. trace(myArray);
  16.  
  17. // OUTPUT: 0,1,2,3,4,5
  18. // OUTPUT: 5,0,1,2,3,4
  19. // OUTPUT: 4,5,0,1,2,3
  20. // OUTPUT: 3,4,5,0,1,2

Report this snippet  

You need to login to post a comment.