Return to Snippet

Revision: 24613
at March 5, 2010 05:09 by adrianparr


Initial Code
function putLastItemOfArrayAtBeginning($a:Array):Array
{
	$a.unshift($a[$a.length-1]);
	$a.pop();
	return $a;
}

var myArray:Array = new Array(0,1,2,3,4,5);
trace(myArray);
myArray = putLastItemOfArrayAtBeginning(myArray);
trace(myArray);
myArray = putLastItemOfArrayAtBeginning(myArray);
trace(myArray);
myArray = putLastItemOfArrayAtBeginning(myArray);
trace(myArray);

// OUTPUT: 0,1,2,3,4,5
// OUTPUT: 5,0,1,2,3,4
// OUTPUT: 4,5,0,1,2,3
// OUTPUT: 3,4,5,0,1,2

Initial URL

                                

Initial Description

                                

Initial Title
AS3 Put Last Item of Array at the Beginning

Initial Tags
array

Initial Language
ActionScript 3