Return to Snippet

Revision: 43241
at March 20, 2011 03:22 by kanuwadhwa


Updated Code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
	<mx:Script>
		<![CDATA[
			// second highest element in an array
			public var arr:Array = new Array("1", "2", "3", "4", "5", "6", "7","8"); // ("2", "1", "4", "3", "6", "5", "8", "7");
			public var swapArr:Array = new Array();
			public function init():void{
				for(var i=0;i<arr.length;i++)
				{
					txt.text += "\n hi " +i;
					var a = arr[i]; 
					var b = arr[i+1];
					
					a = a^b;
					b = a^b;
					a = a^b;
					txt.text += "\n "+a+" ???? "+b;
					
					swapArr.push(a);
					swapArr.push(b);
					if(i<arr.length){
						i++;
					}	
				}
				
				for(var k=0;k<swapArr.length;k++){
					txt.text += "\n "+swapArr[k];					
				}
			}			
		]]>
	</mx:Script>
	<mx:TextArea x="118" y="57" width="553" height="412" id="txt"/>
</mx:Application>

Revision: 43240
at March 20, 2011 03:20 by kanuwadhwa


Initial Code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
	<mx:Script>
		<![CDATA[
			// second highest element in an array
			public var arr:Array = new Array("1", "2", "3", "4", "5", "6", "7","8"); // ("2", "1", "4", "3", "6", "5", "8", "7");
			public var swapArr:Array = new Array();
			public function init():void{
				for(var i=0;i<arr.length;i++)
				{
					txt.text += "\n hi " +i;
					var a = arr[i]; 
					var b = arr[i+1];
					
					a = a^b;
					b = a^b;
					a = a^b;
					txt.text += "\n "+a+" ???? "+b;
					
					swapArr.push(a);
					swapArr.push(b);
					if(i<arr.length){
						i++;
					}	
				}
				
				for(var k=0;k<swapArr.length;k++){
					txt.text += "\n "+swapArr[k];					
				}
			}
			
		]]>
	</mx:Script>
	<mx:TextArea x="118" y="57" width="553" height="412" id="txt"/>
</mx:Application>

Initial URL

                                

Initial Description
Looking forward for the most optimized solution for the same

Initial Title
swapping every 2 numbers with each other in an array

Initial Tags
actionscript, flash, Flex

Initial Language
ActionScript 3