/ Published in: ActionScript 3
Looking forward for the most optimized solution for the same
Expand |
Embed | Plain Text
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ private var str:String = "abcba"; public function init():void{ var len:int = str.length; for (var i:int = 0; i < len/2; i++) { var c1:String = str.charAt(i); var c2:String = str.charAt(len - i - 1); // 5-0-1 = 4, 5-1-1=3, 5-2-1 =2 txt.text = "\n f1>> "+c1+ " >>>b1>> "+c2 if (c1 != c2) { txt.text += "\n false"; } else { txt.text += "\n true"; } } } ]]> </mx:Script> <mx:TextArea x="118" y="57" width="553" height="412" id="txt"/> </mx:Application>
Comments
Subscribe to comments
You need to login to post a comment.

This is not completely correct. You need to add a break, otherwise it shows true when only the character(s) in the middle are equal:
if (c1 != c2){ txt.text += "\n false"; break; }else{ txt.text += "\n true"; }